FossilRepo

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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button