Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2bd3bd2

Browse files
committed
Update README.md, add explanation about return types; implement command line argument parsing in server.py to support returning HTML content or file path.
1 parenta522fc1 commit2bd3bd2

File tree

2 files changed

+79
-23
lines changed

2 files changed

+79
-23
lines changed

‎README.md‎

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,69 @@ Add this server to your `claude_desktop_config.json`:
3333
"mcpServers": {
3434
"mindmap": {
3535
"command":"uvx",
36-
"args": ["mindmap-mcp-server"]
36+
"args": ["mindmap-mcp-server","--return-type","html"]
3737
}
3838
}
3939
}
4040
```
41+
42+
or
43+
44+
recommended:
45+
46+
```json
47+
{
48+
"mcpServers": {
49+
"mindmap": {
50+
"command":"uvx",
51+
"args": ["mindmap-mcp-server","--return-type","filePath"]
52+
}
53+
}
54+
}
55+
```
56+
57+
we use`--return-type` to specify the return type of the mindmap content, you can choose`html` or`filePath` according to your needs.
58+
`html` will return the entire HTML content of the mindmap, which you can preview in your AI client's artifact;
59+
60+
![return_html_content](https://raw.githubusercontent.com/YuChenSSR/pics/master/imgs/2025-03-20/qAEimhwZJDQ3NBLs.png)
61+
62+
![html_preview](https://raw.githubusercontent.com/YuChenSSR/pics/master/imgs/2025-03-20/yZKwbaMcY7lLdKua.png)
63+
64+
`filePath` will save the mindmap to a file and return the file path,which you can open in your browser. It can**save your tokens** !
65+
66+
![generate_file](https://raw.githubusercontent.com/YuChenSSR/pics/master/imgs/2025-03-20/WDqlWhsoiAYpLmBF.png)
67+
68+
![file_to_open](https://raw.githubusercontent.com/YuChenSSR/pics/master/imgs/2025-03-20/jfRIDc5mfvNtKykC.png)
69+
4170
2. Using a specific Python file in this repository:
4271

72+
73+
```json
74+
{
75+
"mcpServers": {
76+
"mindmap": {
77+
"command":"python",
78+
"args": ["/path/to/your/mindmap_mcp_server/server.py","--return-type","html"]
79+
}
80+
}
81+
}
82+
```
83+
84+
or
85+
4386
```json
4487
{
4588
"mcpServers": {
4689
"mindmap": {
4790
"command":"python",
48-
"args": ["/path/to/your/mindmap_mcp_server/server.py"]
91+
"args": ["/path/to/your/mindmap_mcp_server/server.py","--return-type","filePath"]
4992
}
5093
}
5194
}
5295
```
96+
97+
98+
5399
3. Using docker:
54100

55101
First, you pull the image:
@@ -151,9 +197,10 @@ markdown content
151197
```
152198
"
153199

154-
and more
200+
and more
155201

156202

157203
##License
158204

159-
This project is licensed under the MIT License - see the[LICENSE](LICENSE) file for details.
205+
This project is licensed under the MIT License.
206+
For more details, please see the LICENSE file in[this project repository](https://github.com/YuChenSSR/mindmap-mcp-server)

‎mindmap_mcp_server/server.py‎

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,21 @@
77
importos
88
importshutil
99
importsys
10+
importargparse
1011
frompathlibimportPath
1112
frommcp.server.fastmcpimportFastMCP
1213

14+
# 解析命令行参数
15+
defparse_arguments():
16+
parser=argparse.ArgumentParser(description='MCP Server for converting Markdown to mindmaps')
17+
parser.add_argument('--return-type',choices=['html','filePath'],default='html',
18+
help='Whether to return HTML content or file path. Default: html')
19+
returnparser.parse_args()
20+
21+
# 全局配置
22+
args=parse_arguments()
23+
RETURN_TYPE=args.return_type
24+
1325
# Initialize FastMCP server
1426
mcp=FastMCP("mindmap-server")
1527

@@ -23,21 +35,15 @@ async def create_temp_file(content: str, extension: str) -> str:
2335

2436
returnfile_path
2537

26-
asyncdefrun_mindmap(input_file:str,output_file:str=None,offline:bool=False,no_toolbar:bool=False)->str:
27-
"""Runmaindmapmarkmap-cli on the input file and return the path to the output file."""
38+
asyncdefrun_mindmap(input_file:str,output_file:str=None)->str:
39+
"""Run markmap-cli on the input file and return the path to the output file."""
2840
args= ['npx','-y','markmap-cli',input_file,'--no-open']
2941

3042
ifoutput_file:
3143
args.extend(['-o',output_file])
3244
else:
3345
output_file=os.path.splitext(input_file)[0]+'.html'
3446

35-
ifoffline:
36-
args.append('--offline')
37-
38-
ifno_toolbar:
39-
args.append('--no-toolbar')
40-
4147
try:
4248
process=awaitasyncio.create_subprocess_exec(
4349
*args,
@@ -63,34 +69,29 @@ async def get_html_content(file_path: str) -> str:
6369
@mcp.tool()
6470
asyncdefconvert_markdown_to_mindmap(
6571
markdown_content:str,# The Markdown content to convert
66-
return_type:str,# Whether to return 'html' content or 'filePath'
67-
offline:bool=False,# Generate offline-capable HTML with all assets inlined
68-
no_toolbar:bool=False# Hide the toolbar in the generated mindmap
6972
)->str:
7073
"""Convert Markdown content to a mindmap mind map.
7174
7275
Args:
7376
markdown_content: The Markdown content to convert
74-
return_type: Either 'html' to return the HTML content, or 'filePath' to return the file path
75-
offline: Whether to generate offline-capable HTML with all assets inlined
76-
no_toolbar: Whether to hide the toolbar in the generated mindmap
7777
7878
Returns:
79-
Either the HTML content or the file path to the generated HTML
79+
Either the HTML content or the file path to the generated HTML,
80+
depending on the --return-type server argument
8081
"""
8182
try:
8283
# Create a temporary markdown file
8384
input_file=awaitcreate_temp_file(markdown_content,'.md')
8485

8586
# Run mindmap on it
86-
output_file=awaitrun_mindmap(input_file,offline=offline,no_toolbar=no_toolbar)
87+
output_file=awaitrun_mindmap(input_file)
8788

8889
# Check if the output file exists
8990
ifnotos.path.exists(output_file):
9091
raiseRuntimeError(f"Output file was not created:{output_file}")
9192

92-
# Return either the HTML content or the file path
93-
ifreturn_type=='html':
93+
# Return either the HTML content or the file path based on command line arg
94+
ifRETURN_TYPE=='html':
9495
html_content=awaitget_html_content(output_file)
9596
returnhtml_content
9697
else:
@@ -100,8 +101,16 @@ async def convert_markdown_to_mindmap(
100101

101102
defmain():
102103
"""Entry point for the mindmap-mcp-server command."""
104+
globalargs,RETURN_TYPE
105+
106+
# 再次解析参数以确保在作为入口点运行时也能获取参数
107+
args=parse_arguments()
108+
RETURN_TYPE=args.return_type
109+
110+
print(f"Starting mindmap-mcp-server with return type:{RETURN_TYPE}",file=sys.stderr)
111+
103112
# Initialize and run the server
104113
mcp.run(transport='stdio')
105114

106115
if__name__=="__main__":
107-
main()
116+
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp