-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_server.py
More file actions
36 lines (28 loc) · 937 Bytes
/
run_server.py
File metadata and controls
36 lines (28 loc) · 937 Bytes
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
"""
Sample script demonstrating how to use OpenAPI2MCP.
"""
import os
import json
import asyncio
from openapi2mcp.server import MCPServer
import uvicorn
async def main():
# Path to OpenAPI specification file
spec_file = os.path.join(os.path.dirname(__file__), "sample_api.yaml")
# Create MCP server
server = MCPServer(spec_files=[spec_file])
# Get tools
tools = server.tools
# Print available tools
print(f"Generated {len(tools)} MCP tools:")
for i, tool in enumerate(tools, 1):
print(f"{i}. {tool['name']} - {tool.get('description', '').split('\n')[0]}")
# Run the server
app = server.get_app()
# Start the server
print("\nStarting MCP server on http://127.0.0.1:8000")
print("Press Ctrl+C to stop")
# Run the server (this will block)
uvicorn.run(app, host="127.0.0.1", port=8000)
if __name__ == "__main__":
asyncio.run(main())