-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.py
More file actions
99 lines (72 loc) · 2.51 KB
/
server.py
File metadata and controls
99 lines (72 loc) · 2.51 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
"""
Webhook.site MCP Server
A Model Context Protocol (MCP) server for interacting with webhook.site.
Provides tools for creating, managing, and monitoring webhooks.
Usage:
python server.py
Architecture:
server.py - MCP entry point (this file)
handlers/ - Tool call routing
services/ - Business logic
models/ - Data models and schemas
utils/ - HTTP client utilities
"""
from __future__ import annotations
import asyncio
import sys
from pathlib import Path
from typing import Any
# Add project root to path for imports
PROJECT_ROOT = Path(__file__).parent
sys.path.insert(0, str(PROJECT_ROOT))
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp.types import Tool, TextContent
from models.schemas import TOOL_DEFINITIONS
from handlers.tool_handlers import ToolHandler
from utils.http_client import WebhookHttpClient
# =============================================================================
# SERVER INITIALIZATION
# =============================================================================
server = Server("webhook-site-mcp")
@server.list_tools()
async def list_tools() -> list[Tool]:
"""Return all available webhook.site tools.
Returns:
List of Tool definitions from models/schemas.py
"""
return TOOL_DEFINITIONS
@server.call_tool()
async def call_tool(name: str, arguments: dict[str, Any]) -> list[TextContent]:
"""Handle MCP tool calls.
Routes tool calls through the handler layer which delegates
to appropriate services.
Args:
name: Tool name
arguments: Tool arguments
Returns:
List of TextContent responses
"""
async with WebhookHttpClient() as client:
handler = ToolHandler(client)
return await handler.handle(name, arguments)
# =============================================================================
# MAIN ENTRY POINT
# =============================================================================
async def main() -> None:
"""Run the MCP server.
Starts the stdio transport and runs the server
until interrupted.
"""
async with stdio_server() as (read_stream, write_stream):
await server.run(
read_stream,
write_stream,
server.create_initialization_options(),
)
def run_server() -> None:
"""Synchronous entry point for console script."""
asyncio.run(main())
if __name__ == "__main__":
run_server()