|
1 | 1 | """
|
2 | 2 | A Nexus service that presents the interface of an MCP server.
|
3 |
| -It is backed by a Temporal workflow. |
| 3 | +Returns mock data for testing the transport layer. |
4 | 4 | """
|
5 | 5 |
|
6 |
| -import uuid |
7 | 6 | from dataclasses import dataclass
|
8 | 7 |
|
9 | 8 | import nexusrpc
|
|
12 | 11 | CallToolResult,
|
13 | 12 | ListToolsRequest,
|
14 | 13 | ListToolsResult,
|
| 14 | + TextContent, |
| 15 | + Tool, |
15 | 16 | )
|
16 |
| -from temporalio import nexus |
17 | 17 |
|
18 | 18 |
|
19 | 19 | @dataclass
|
@@ -42,29 +42,72 @@ class MCPServerNexusService:
|
42 | 42 |
|
43 | 43 | @nexusrpc.handler.service_handler(service=MCPServerNexusService)
|
44 | 44 | class MCPServerNexusServiceHandler:
|
45 |
| - @nexus.workflow_run_operation |
| 45 | + @nexusrpc.handler.sync_operation |
46 | 46 | async def start(
|
47 |
| - self, ctx: nexus.WorkflowRunOperationContext, input: MCPServerStartInput |
48 |
| - ) -> nexus.WorkflowHandle[None]: |
49 |
| - return await ctx.start_workflow( |
50 |
| - input.mcp_server_workflow_name, |
51 |
| - id=str(uuid.uuid4()), |
52 |
| - ) |
| 47 | + self, ctx: nexusrpc.handler.StartOperationContext, input: MCPServerStartInput |
| 48 | + ) -> None: |
| 49 | + # Mock implementation - just return None |
| 50 | + return None |
53 | 51 |
|
54 | 52 | @nexusrpc.handler.sync_operation
|
55 | 53 | async def call_tool(
|
56 | 54 | self, ctx: nexusrpc.handler.StartOperationContext, input: CallToolInput
|
57 | 55 | ) -> CallToolResult:
|
58 |
| - workflow_handle = nexus.WorkflowHandle.from_token( |
59 |
| - input.operation_token |
60 |
| - )._to_client_workflow_handle(nexus.client()) |
61 |
| - return await workflow_handle.execute_update("call_tool", input.request) |
| 56 | + # Mock implementation - return a sample response |
| 57 | + if input.request.params.name == "sequentialthinking": |
| 58 | + args = input.request.params.arguments or {} |
| 59 | + thought = ( |
| 60 | + args.get("thought", "Mock thought") |
| 61 | + if isinstance(args, dict) |
| 62 | + else "Mock thought" |
| 63 | + ) |
| 64 | + thought_number = ( |
| 65 | + args.get("thoughtNumber", 1) if isinstance(args, dict) else 1 |
| 66 | + ) |
| 67 | + total_thoughts = ( |
| 68 | + args.get("totalThoughts", 3) if isinstance(args, dict) else 3 |
| 69 | + ) |
| 70 | + |
| 71 | + response_text = f"Mock response: Processed thought {thought_number}/{total_thoughts}: {thought}" |
| 72 | + |
| 73 | + return CallToolResult( |
| 74 | + content=[TextContent(type="text", text=response_text)] |
| 75 | + ) |
| 76 | + else: |
| 77 | + return CallToolResult( |
| 78 | + content=[ |
| 79 | + TextContent( |
| 80 | + type="text", |
| 81 | + text=f"Mock response: Tool {input.request.params.name} called", |
| 82 | + ) |
| 83 | + ] |
| 84 | + ) |
62 | 85 |
|
63 | 86 | @nexusrpc.handler.sync_operation
|
64 | 87 | async def list_tools(
|
65 | 88 | self, ctx: nexusrpc.handler.StartOperationContext, input: ListToolsInput
|
66 | 89 | ) -> ListToolsResult:
|
67 |
| - workflow_handle = nexus.WorkflowHandle.from_token( |
68 |
| - input.operation_token |
69 |
| - )._to_client_workflow_handle(nexus.client()) |
70 |
| - return await workflow_handle.query("list_tools", input.request) |
| 90 | + # Mock implementation - return sequential thinking tool |
| 91 | + return ListToolsResult( |
| 92 | + tools=[ |
| 93 | + Tool( |
| 94 | + name="sequentialthinking", |
| 95 | + description="A tool for sequential thinking and problem-solving", |
| 96 | + inputSchema={ |
| 97 | + "type": "object", |
| 98 | + "properties": { |
| 99 | + "thought": {"type": "string"}, |
| 100 | + "thoughtNumber": {"type": "integer"}, |
| 101 | + "totalThoughts": {"type": "integer"}, |
| 102 | + "nextThoughtNeeded": {"type": "boolean"}, |
| 103 | + }, |
| 104 | + "required": [ |
| 105 | + "thought", |
| 106 | + "thoughtNumber", |
| 107 | + "totalThoughts", |
| 108 | + "nextThoughtNeeded", |
| 109 | + ], |
| 110 | + }, |
| 111 | + ) |
| 112 | + ] |
| 113 | + ) |
0 commit comments