Patrick Rathje
commited on
Commit
·
02884b9
1
Parent(s):
3115759
adapt file descriptions to match motion canvas docs
Browse files
app.py
CHANGED
|
@@ -23,25 +23,25 @@ def safe_exec(func, *args, **kwargs):
|
|
| 23 |
|
| 24 |
def read_file(path):
|
| 25 |
"""
|
| 26 |
-
Read the contents of a file at the given path.
|
| 27 |
|
| 28 |
Args:
|
| 29 |
-
path (str): The path to the file to read.
|
| 30 |
|
| 31 |
Returns:
|
| 32 |
-
str: The contents of the file, or an error message if not found.
|
| 33 |
"""
|
| 34 |
return safe_exec(fs.read_file, path)
|
| 35 |
|
| 36 |
def read_multiple_files(paths):
|
| 37 |
"""
|
| 38 |
-
Read the contents of multiple files specified by a comma-separated list of paths.
|
| 39 |
|
| 40 |
Args:
|
| 41 |
-
paths (str): Comma-separated file paths to read.
|
| 42 |
|
| 43 |
Returns:
|
| 44 |
-
str: The concatenated contents of all files, or error messages for files that could not be read.
|
| 45 |
"""
|
| 46 |
path_list = [p.strip() for p in paths.split(',') if p.strip()]
|
| 47 |
|
|
@@ -62,11 +62,11 @@ def read_multiple_files(paths):
|
|
| 62 |
|
| 63 |
def write_file(path, content):
|
| 64 |
"""
|
| 65 |
-
Write content to a file at the given path.
|
| 66 |
|
| 67 |
Args:
|
| 68 |
-
path (str): The path to the file to write.
|
| 69 |
-
content (str): The content to write to the file.
|
| 70 |
|
| 71 |
Returns:
|
| 72 |
str: Success message or error message if the write fails.
|
|
@@ -75,10 +75,10 @@ def write_file(path, content):
|
|
| 75 |
|
| 76 |
def create_directory(path):
|
| 77 |
"""
|
| 78 |
-
Create a directory at the given path, including any necessary parent directories.
|
| 79 |
|
| 80 |
Args:
|
| 81 |
-
path (str): The directory path to create.
|
| 82 |
|
| 83 |
Returns:
|
| 84 |
str: Success message or error message if creation fails.
|
|
@@ -87,10 +87,10 @@ def create_directory(path):
|
|
| 87 |
|
| 88 |
def list_directory(path):
|
| 89 |
"""
|
| 90 |
-
List the contents of a directory at the given path.
|
| 91 |
|
| 92 |
Args:
|
| 93 |
-
path (str): The directory path to list.
|
| 94 |
|
| 95 |
Returns:
|
| 96 |
str: Newline-separated list of directory contents, or error message if listing fails.
|
|
@@ -99,11 +99,11 @@ def list_directory(path):
|
|
| 99 |
|
| 100 |
def move_file(source, destination):
|
| 101 |
"""
|
| 102 |
-
Move a file from source to destination path.
|
| 103 |
|
| 104 |
Args:
|
| 105 |
-
source (str): The source file path.
|
| 106 |
-
destination (str): The destination file path.
|
| 107 |
|
| 108 |
Returns:
|
| 109 |
str: Success message or error message if move fails.
|
|
@@ -112,28 +112,28 @@ def move_file(source, destination):
|
|
| 112 |
|
| 113 |
def search_files(path, pattern, exclude):
|
| 114 |
"""
|
| 115 |
-
Search for files in a directory matching a pattern, excluding specified patterns.
|
| 116 |
|
| 117 |
Args:
|
| 118 |
-
path (str): The directory path to search in.
|
| 119 |
-
pattern (str): The glob pattern to match files.
|
| 120 |
exclude (str): Comma-separated patterns to exclude from results.
|
| 121 |
|
| 122 |
Returns:
|
| 123 |
-
str: Newline-separated list of matching file paths, or error message if search fails.
|
| 124 |
"""
|
| 125 |
exclude_list = [e.strip() for e in exclude.split(',') if e.strip()]
|
| 126 |
return '\n'.join(safe_exec(fs.search_files, path, pattern, exclude_list))
|
| 127 |
|
| 128 |
def directory_tree(path):
|
| 129 |
"""
|
| 130 |
-
Get a tree representation of the directory at the given path.
|
| 131 |
|
| 132 |
Args:
|
| 133 |
-
path (str): The directory path to show as a tree.
|
| 134 |
|
| 135 |
Returns:
|
| 136 |
-
str: The directory tree as a string, or error message if operation fails.
|
| 137 |
"""
|
| 138 |
return safe_exec(fs.directory_tree, path)
|
| 139 |
|
|
@@ -141,7 +141,8 @@ with gr.Blocks() as demo:
|
|
| 141 |
|
| 142 |
gr.Markdown("""
|
| 143 |
# Motion Canvas Docs MCP Server
|
| 144 |
-
This is a simple MCP server based on Gradio that allows you to read
|
|
|
|
| 145 |
It is based on the Gradio Fileserver MCP Server: https://huggingface.co/spaces/prathje/gradio_fileserver_mcp
|
| 146 |
The API is a simpler version of https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem
|
| 147 |
""")
|
|
|
|
| 23 |
|
| 24 |
def read_file(path):
|
| 25 |
"""
|
| 26 |
+
Read the contents of a Motion Canvas documentation file at the given path.
|
| 27 |
|
| 28 |
Args:
|
| 29 |
+
path (str): The path to the documentation file to read.
|
| 30 |
|
| 31 |
Returns:
|
| 32 |
+
str: The contents of the documentation file, or an error message if not found.
|
| 33 |
"""
|
| 34 |
return safe_exec(fs.read_file, path)
|
| 35 |
|
| 36 |
def read_multiple_files(paths):
|
| 37 |
"""
|
| 38 |
+
Read the contents of multiple Motion Canvas documentation files specified by a comma-separated list of paths.
|
| 39 |
|
| 40 |
Args:
|
| 41 |
+
paths (str): Comma-separated documentation file paths to read.
|
| 42 |
|
| 43 |
Returns:
|
| 44 |
+
str: The concatenated contents of all documentation files, or error messages for files that could not be read.
|
| 45 |
"""
|
| 46 |
path_list = [p.strip() for p in paths.split(',') if p.strip()]
|
| 47 |
|
|
|
|
| 62 |
|
| 63 |
def write_file(path, content):
|
| 64 |
"""
|
| 65 |
+
Write content to a Motion Canvas documentation file at the given path.
|
| 66 |
|
| 67 |
Args:
|
| 68 |
+
path (str): The path to the documentation file to write.
|
| 69 |
+
content (str): The content to write to the documentation file.
|
| 70 |
|
| 71 |
Returns:
|
| 72 |
str: Success message or error message if the write fails.
|
|
|
|
| 75 |
|
| 76 |
def create_directory(path):
|
| 77 |
"""
|
| 78 |
+
Create a directory for Motion Canvas documentation at the given path, including any necessary parent directories.
|
| 79 |
|
| 80 |
Args:
|
| 81 |
+
path (str): The documentation directory path to create.
|
| 82 |
|
| 83 |
Returns:
|
| 84 |
str: Success message or error message if creation fails.
|
|
|
|
| 87 |
|
| 88 |
def list_directory(path):
|
| 89 |
"""
|
| 90 |
+
List the contents of a directory containing Motion Canvas documentation at the given path.
|
| 91 |
|
| 92 |
Args:
|
| 93 |
+
path (str): The documentation directory path to list.
|
| 94 |
|
| 95 |
Returns:
|
| 96 |
str: Newline-separated list of directory contents, or error message if listing fails.
|
|
|
|
| 99 |
|
| 100 |
def move_file(source, destination):
|
| 101 |
"""
|
| 102 |
+
Move a Motion Canvas documentation file from source to destination path.
|
| 103 |
|
| 104 |
Args:
|
| 105 |
+
source (str): The source documentation file path.
|
| 106 |
+
destination (str): The destination documentation file path.
|
| 107 |
|
| 108 |
Returns:
|
| 109 |
str: Success message or error message if move fails.
|
|
|
|
| 112 |
|
| 113 |
def search_files(path, pattern, exclude):
|
| 114 |
"""
|
| 115 |
+
Search for Motion Canvas documentation files in a directory matching a pattern, excluding specified patterns.
|
| 116 |
|
| 117 |
Args:
|
| 118 |
+
path (str): The documentation directory path to search in.
|
| 119 |
+
pattern (str): The glob pattern to match documentation files.
|
| 120 |
exclude (str): Comma-separated patterns to exclude from results.
|
| 121 |
|
| 122 |
Returns:
|
| 123 |
+
str: Newline-separated list of matching documentation file paths, or error message if search fails.
|
| 124 |
"""
|
| 125 |
exclude_list = [e.strip() for e in exclude.split(',') if e.strip()]
|
| 126 |
return '\n'.join(safe_exec(fs.search_files, path, pattern, exclude_list))
|
| 127 |
|
| 128 |
def directory_tree(path):
|
| 129 |
"""
|
| 130 |
+
Get a tree representation of the Motion Canvas documentation directory at the given path.
|
| 131 |
|
| 132 |
Args:
|
| 133 |
+
path (str): The documentation directory path to show as a tree.
|
| 134 |
|
| 135 |
Returns:
|
| 136 |
+
str: The documentation directory tree as a string, or error message if operation fails.
|
| 137 |
"""
|
| 138 |
return safe_exec(fs.directory_tree, path)
|
| 139 |
|
|
|
|
| 141 |
|
| 142 |
gr.Markdown("""
|
| 143 |
# Motion Canvas Docs MCP Server
|
| 144 |
+
This is a simple MCP server based on Gradio that allows you to search and read documentation files for Motion Canvas.
|
| 145 |
+
All functions and tabs are designed to interact with the Motion Canvas documentation files only.
|
| 146 |
It is based on the Gradio Fileserver MCP Server: https://huggingface.co/spaces/prathje/gradio_fileserver_mcp
|
| 147 |
The API is a simpler version of https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem
|
| 148 |
""")
|