Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
4f116ec
1
Parent(s):
6c1b819
Simplify MCP arch #3
Browse files
agent.py
CHANGED
|
@@ -18,6 +18,7 @@ from pathlib import Path
|
|
| 18 |
try:
|
| 19 |
from mcp.server import Server
|
| 20 |
from mcp.types import Tool, TextContent, ImageContent, EmbeddedResource
|
|
|
|
| 21 |
except ImportError:
|
| 22 |
print("Error: MCP SDK not installed. Install with: pip install mcp", file=sys.stderr)
|
| 23 |
sys.exit(1)
|
|
@@ -281,15 +282,29 @@ async def main():
|
|
| 281 |
|
| 282 |
try:
|
| 283 |
async with stdio_server() as streams:
|
| 284 |
-
#
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
logger.info("MCP server ready")
|
| 288 |
try:
|
| 289 |
# Run the server - it will automatically handle the initialization handshake
|
| 290 |
await app.run(
|
| 291 |
read_stream=streams[0],
|
| 292 |
-
write_stream=streams[1]
|
|
|
|
| 293 |
)
|
| 294 |
except Exception as run_error:
|
| 295 |
logger.error(f"Error in app.run(): {run_error}")
|
|
|
|
| 18 |
try:
|
| 19 |
from mcp.server import Server
|
| 20 |
from mcp.types import Tool, TextContent, ImageContent, EmbeddedResource
|
| 21 |
+
from mcp.server.models import InitializationOptions
|
| 22 |
except ImportError:
|
| 23 |
print("Error: MCP SDK not installed. Install with: pip install mcp", file=sys.stderr)
|
| 24 |
sys.exit(1)
|
|
|
|
| 282 |
|
| 283 |
try:
|
| 284 |
async with stdio_server() as streams:
|
| 285 |
+
# Prepare server capabilities for initialization
|
| 286 |
+
try:
|
| 287 |
+
if hasattr(app, "get_capabilities"):
|
| 288 |
+
server_capabilities = app.get_capabilities()
|
| 289 |
+
else:
|
| 290 |
+
server_capabilities = {}
|
| 291 |
+
except Exception as cap_error:
|
| 292 |
+
logger.warning(f"Failed to gather server capabilities: {cap_error}")
|
| 293 |
+
server_capabilities = {}
|
| 294 |
+
|
| 295 |
+
init_options = InitializationOptions(
|
| 296 |
+
server_name="gemini-mcp-server",
|
| 297 |
+
server_version="1.0.0",
|
| 298 |
+
capabilities=server_capabilities,
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
logger.info("MCP server ready")
|
| 302 |
try:
|
| 303 |
# Run the server - it will automatically handle the initialization handshake
|
| 304 |
await app.run(
|
| 305 |
read_stream=streams[0],
|
| 306 |
+
write_stream=streams[1],
|
| 307 |
+
initialization_options=init_options,
|
| 308 |
)
|
| 309 |
except Exception as run_error:
|
| 310 |
logger.error(f"Error in app.run(): {run_error}")
|