-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmcp-server.py
More file actions
60 lines (53 loc) · 1.74 KB
/
Copy pathmcp-server.py
File metadata and controls
60 lines (53 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
import asyncio
import json
import sys
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp.types import Tool, TextContent
import mansnip
app = Server("manpage-query")
@app.list_tools()
async def list_tools() -> list[Tool]:
return [
Tool(
name="manpage_query",
description="return a contextual snippet from a manpage",
inputSchema={
"type": "object",
"properties": {
"section": {
"type": "string",
"description": "man page section if needed for disambiguation"
},
"manpage": {
"type": "string",
"description": "man page to retrieve"
},
"query": {
"type": "string",
"description": "term to look up"
}
},
"required": ["manpage", "query"]
}
)
]
@app.call_tool()
async def call_tool(name: str, arguments: dict) -> list[TextContent]:
if name == "manpage_query":
section = arguments.get("section") or ""
page = arguments.get("manpage")
query = arguments.get("query")
res = mansnip.mansnip(section, page, query, {'MANSNIP_LLM': 1})
return [TextContent(type="text", text=res)]
raise ValueError(f"Unknown tool: {name}")
async def main():
async with stdio_server() as (read_stream, write_stream):
await app.run(
read_stream,
write_stream,
app.create_initialization_options()
)
if __name__ == "__main__":
asyncio.run(main())