galcan commited on
Commit
102fdc3
·
1 Parent(s): 6b988ac
Files changed (1) hide show
  1. app.py +71 -36
app.py CHANGED
@@ -325,50 +325,85 @@ async def list_docs():
325
  async def mcp_sse():
326
  """MCP SSE endpoint for mcp-remote"""
327
  async def event_generator():
328
- # Send initial MCP server info
329
- yield f"data: {json.dumps({'type': 'mcp_server', 'name': 'mcp-docs-server', 'version': '1.0.0'})}\n\n"
330
-
331
- # Send available tools
332
- tools = [
333
- {
334
- "name": "search_docs",
335
- "description": "Search through MCP documentation chunks",
336
- "inputSchema": {
337
- "type": "object",
338
- "properties": {
339
- "query": {"type": "string", "description": "Search query"},
340
- "limit": {"type": "integer", "description": "Maximum number of results", "default": 5}
341
- },
342
- "required": ["query"]
343
- }
344
- },
345
- {
346
- "name": "get_chunk",
347
- "description": "Get a specific documentation chunk by ID",
348
- "inputSchema": {
349
- "type": "object",
350
- "properties": {
351
- "chunk_id": {"type": "string", "description": "Chunk ID to retrieve"}
352
  },
353
- "required": ["chunk_id"]
354
- }
355
- },
356
- {
357
- "name": "list_docs",
358
- "description": "List all available documents",
359
- "inputSchema": {
360
- "type": "object",
361
- "properties": {}
362
  }
363
  }
364
- ]
 
365
 
366
- yield f"data: {json.dumps({'type': 'tools', 'tools': tools})}\n\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
 
368
  # Keep connection alive
369
  while True:
370
  await asyncio.sleep(30)
371
- yield f"data: {json.dumps({'type': 'heartbeat', 'timestamp': asyncio.get_event_loop().time()})}\n\n"
372
 
373
  return StreamingResponse(
374
  event_generator(),
 
325
  async def mcp_sse():
326
  """MCP SSE endpoint for mcp-remote"""
327
  async def event_generator():
328
+ # Send MCP initialization response (correct format from docs)
329
+ init_response = {
330
+ "jsonrpc": "2.0",
331
+ "id": 1,
332
+ "result": {
333
+ "protocolVersion": "2025-06-18",
334
+ "capabilities": {
335
+ "tools": {
336
+ "listChanged": True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  },
338
+ "resources": {}
339
+ },
340
+ "serverInfo": {
341
+ "name": "mcp-docs-server",
342
+ "version": "1.0.0"
 
 
 
 
343
  }
344
  }
345
+ }
346
+ yield f"data: {json.dumps(init_response)}\n\n"
347
 
348
+ # Send tools list response (correct format from docs)
349
+ tools_response = {
350
+ "jsonrpc": "2.0",
351
+ "id": 2,
352
+ "result": {
353
+ "tools": [
354
+ {
355
+ "name": "search_docs",
356
+ "title": "Search Documentation",
357
+ "description": "Search through MCP documentation chunks",
358
+ "inputSchema": {
359
+ "type": "object",
360
+ "properties": {
361
+ "query": {
362
+ "type": "string",
363
+ "description": "Search query for MCP documentation"
364
+ },
365
+ "limit": {
366
+ "type": "integer",
367
+ "description": "Maximum number of results",
368
+ "default": 5
369
+ }
370
+ },
371
+ "required": ["query"]
372
+ }
373
+ },
374
+ {
375
+ "name": "get_chunk",
376
+ "title": "Get Documentation Chunk",
377
+ "description": "Get a specific documentation chunk by ID",
378
+ "inputSchema": {
379
+ "type": "object",
380
+ "properties": {
381
+ "chunk_id": {
382
+ "type": "string",
383
+ "description": "Chunk ID to retrieve"
384
+ }
385
+ },
386
+ "required": ["chunk_id"]
387
+ }
388
+ },
389
+ {
390
+ "name": "list_docs",
391
+ "title": "List Documents",
392
+ "description": "List all available documents",
393
+ "inputSchema": {
394
+ "type": "object",
395
+ "properties": {}
396
+ }
397
+ }
398
+ ]
399
+ }
400
+ }
401
+ yield f"data: {json.dumps(tools_response)}\n\n"
402
 
403
  # Keep connection alive
404
  while True:
405
  await asyncio.sleep(30)
406
+ yield f"data: {json.dumps({'jsonrpc': '2.0', 'method': 'ping', 'params': {}})}\n\n"
407
 
408
  return StreamingResponse(
409
  event_generator(),