|
1
|
"""Fossilrepo MCP Server -- exposes repo operations to AI tools. |
|
2
|
|
|
3
|
Runs as a standalone process communicating over stdio using JSON-RPC 2.0 |
|
4
|
(Model Context Protocol). Imports Django models directly for DB access. |
|
5
|
""" |
|
6
|
|
|
7
|
import json |
|
8
|
import os |
|
9
|
|
|
10
|
# Setup Django before any model imports |
|
11
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") |
|
12
|
|
|
13
|
import django # noqa: E402 |
|
14
|
|
|
15
|
django.setup() |
|
16
|
|
|
17
|
from mcp.server import Server # noqa: E402 |
|
18
|
from mcp.server.stdio import stdio_server # noqa: E402 |
|
19
|
from mcp.types import TextContent # noqa: E402 |
|
20
|
|
|
21
|
from mcp_server.tools import TOOLS, execute_tool # noqa: E402 |
|
22
|
|
|
23
|
server = Server("fossilrepo") |
|
24
|
|
|
25
|
|
|
26
|
@server.list_tools() |
|
27
|
async def list_tools(): |
|
28
|
return TOOLS |
|
29
|
|
|
30
|
|
|
31
|
@server.call_tool() |
|
32
|
async def call_tool(name: str, arguments: dict): |
|
33
|
result = execute_tool(name, arguments) |
|
34
|
return [TextContent(type="text", text=json.dumps(result, indent=2, default=str))] |
|
35
|
|
|
36
|
|
|
37
|
async def main(): |
|
38
|
async with stdio_server() as (read_stream, write_stream): |
|
39
|
await server.run(read_stream, write_stream, server.create_initialization_options()) |
|
40
|
|