mcp-mesh 0.4.2__py3-none-any.whl → 0.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. _mcp_mesh/__init__.py +14 -3
  2. _mcp_mesh/engine/__init__.py +12 -1
  3. _mcp_mesh/engine/async_mcp_client.py +2 -2
  4. _mcp_mesh/engine/decorator_registry.py +98 -8
  5. _mcp_mesh/engine/dependency_injector.py +249 -71
  6. _mcp_mesh/engine/full_mcp_proxy.py +4 -4
  7. _mcp_mesh/engine/http_wrapper.py +9 -20
  8. _mcp_mesh/engine/mcp_client_proxy.py +1 -1
  9. _mcp_mesh/engine/unified_mcp_proxy.py +813 -0
  10. _mcp_mesh/generated/.openapi-generator/FILES +2 -0
  11. _mcp_mesh/generated/mcp_mesh_registry_client/__init__.py +2 -0
  12. _mcp_mesh/generated/mcp_mesh_registry_client/api/__init__.py +1 -0
  13. _mcp_mesh/generated/mcp_mesh_registry_client/api/tracing_api.py +305 -0
  14. _mcp_mesh/generated/mcp_mesh_registry_client/models/__init__.py +1 -0
  15. _mcp_mesh/generated/mcp_mesh_registry_client/models/agent_info.py +10 -1
  16. _mcp_mesh/generated/mcp_mesh_registry_client/models/mesh_agent_registration.py +4 -4
  17. _mcp_mesh/generated/mcp_mesh_registry_client/models/trace_event.py +108 -0
  18. _mcp_mesh/pipeline/__init__.py +2 -2
  19. _mcp_mesh/pipeline/api_heartbeat/__init__.py +16 -0
  20. _mcp_mesh/pipeline/api_heartbeat/api_dependency_resolution.py +506 -0
  21. _mcp_mesh/pipeline/api_heartbeat/api_fast_heartbeat_check.py +117 -0
  22. _mcp_mesh/pipeline/api_heartbeat/api_health_check.py +140 -0
  23. _mcp_mesh/pipeline/api_heartbeat/api_heartbeat_orchestrator.py +247 -0
  24. _mcp_mesh/pipeline/api_heartbeat/api_heartbeat_pipeline.py +309 -0
  25. _mcp_mesh/pipeline/api_heartbeat/api_heartbeat_send.py +332 -0
  26. _mcp_mesh/pipeline/api_heartbeat/api_lifespan_integration.py +147 -0
  27. _mcp_mesh/pipeline/api_heartbeat/api_registry_connection.py +104 -0
  28. _mcp_mesh/pipeline/api_startup/__init__.py +20 -0
  29. _mcp_mesh/pipeline/api_startup/api_pipeline.py +61 -0
  30. _mcp_mesh/pipeline/api_startup/api_server_setup.py +367 -0
  31. _mcp_mesh/pipeline/api_startup/fastapi_discovery.py +302 -0
  32. _mcp_mesh/pipeline/api_startup/route_collection.py +56 -0
  33. _mcp_mesh/pipeline/api_startup/route_integration.py +318 -0
  34. _mcp_mesh/pipeline/{heartbeat → mcp_heartbeat}/dependency_resolution.py +19 -183
  35. _mcp_mesh/pipeline/{startup → mcp_startup}/heartbeat_loop.py +1 -1
  36. _mcp_mesh/pipeline/{startup → mcp_startup}/startup_orchestrator.py +170 -5
  37. _mcp_mesh/shared/config_resolver.py +0 -3
  38. _mcp_mesh/shared/logging_config.py +2 -1
  39. _mcp_mesh/tracing/agent_context_helper.py +1 -1
  40. _mcp_mesh/tracing/execution_tracer.py +41 -0
  41. {mcp_mesh-0.4.2.dist-info → mcp_mesh-0.5.1.dist-info}/METADATA +1 -1
  42. {mcp_mesh-0.4.2.dist-info → mcp_mesh-0.5.1.dist-info}/RECORD +61 -43
  43. mesh/__init__.py +3 -1
  44. mesh/decorators.py +143 -1
  45. mesh/types.py +109 -48
  46. /_mcp_mesh/pipeline/{heartbeat → mcp_heartbeat}/__init__.py +0 -0
  47. /_mcp_mesh/pipeline/{heartbeat → mcp_heartbeat}/fast_heartbeat_check.py +0 -0
  48. /_mcp_mesh/pipeline/{heartbeat → mcp_heartbeat}/heartbeat_orchestrator.py +0 -0
  49. /_mcp_mesh/pipeline/{heartbeat → mcp_heartbeat}/heartbeat_pipeline.py +0 -0
  50. /_mcp_mesh/pipeline/{heartbeat → mcp_heartbeat}/heartbeat_send.py +0 -0
  51. /_mcp_mesh/pipeline/{heartbeat → mcp_heartbeat}/lifespan_integration.py +0 -0
  52. /_mcp_mesh/pipeline/{heartbeat → mcp_heartbeat}/registry_connection.py +0 -0
  53. /_mcp_mesh/pipeline/{startup → mcp_startup}/__init__.py +0 -0
  54. /_mcp_mesh/pipeline/{startup → mcp_startup}/configuration.py +0 -0
  55. /_mcp_mesh/pipeline/{startup → mcp_startup}/decorator_collection.py +0 -0
  56. /_mcp_mesh/pipeline/{startup → mcp_startup}/fastapiserver_setup.py +0 -0
  57. /_mcp_mesh/pipeline/{startup → mcp_startup}/fastmcpserver_discovery.py +0 -0
  58. /_mcp_mesh/pipeline/{startup → mcp_startup}/heartbeat_preparation.py +0 -0
  59. /_mcp_mesh/pipeline/{startup → mcp_startup}/startup_pipeline.py +0 -0
  60. {mcp_mesh-0.4.2.dist-info → mcp_mesh-0.5.1.dist-info}/WHEEL +0 -0
  61. {mcp_mesh-0.4.2.dist-info → mcp_mesh-0.5.1.dist-info}/licenses/LICENSE +0 -0
mesh/types.py CHANGED
@@ -3,7 +3,7 @@ MCP Mesh type definitions for dependency injection.
3
3
  """
4
4
 
5
5
  from collections.abc import AsyncIterator
6
- from typing import Any, Protocol
6
+ from typing import Any, Optional, Protocol
7
7
 
8
8
  try:
9
9
  from pydantic_core import core_schema
@@ -15,29 +15,56 @@ except ImportError:
15
15
 
16
16
  class McpMeshAgent(Protocol):
17
17
  """
18
- Protocol for MCP Mesh agent proxies used in dependency injection.
18
+ Unified MCP Mesh agent proxy using FastMCP's built-in client.
19
19
 
20
- Each proxy is bound to a specific remote function and knows exactly what to call.
21
- The registry handles function-to-function mapping, so users don't need to specify function names.
20
+ This protocol now provides all MCP protocol features using FastMCP's superior client
21
+ implementation, replacing both the old basic and advanced proxy types.
22
+
23
+ Features:
24
+ - All MCP protocol methods (tools, resources, prompts)
25
+ - Streaming support with FastMCP's StreamableHttpTransport
26
+ - Session management with notifications
27
+ - Automatic redirect handling (fixes /mcp/ → /mcp issue)
28
+ - CallToolResult objects with structured content parsing
29
+ - Enhanced proxy configuration via kwargs
22
30
 
23
31
  Usage Examples:
24
- @mesh.tool(dependencies=[{"capability": "get_current_date"}]) # Function name as capability
25
- def greet(name: str, date_getter: McpMeshAgent) -> str:
32
+ @mesh.tool(dependencies=["date-service"])
33
+ def greet(name: str, date_service: McpMeshAgent) -> str:
26
34
  # Simple call - proxy knows which remote function to invoke
27
- current_date = date_getter()
35
+ current_date = date_service()
28
36
 
29
37
  # With arguments
30
- current_date = date_getter({"format": "ISO"})
38
+ current_date = date_service({"format": "ISO"})
31
39
 
32
40
  # Explicit invoke (same as call)
33
- current_date = date_getter.invoke({"format": "ISO"})
41
+ current_date = date_service.invoke({"format": "ISO"})
34
42
 
35
43
  return f"Hello {name}, today is {current_date}"
36
44
 
37
- The proxy is bound to one specific remote function, eliminating the need to specify function names.
45
+ @mesh.tool(dependencies=["file-service"])
46
+ async def process_files(file_service: McpMeshAgent) -> str:
47
+ # Full MCP Protocol usage
48
+ tools = await file_service.list_tools()
49
+ resources = await file_service.list_resources()
50
+ prompts = await file_service.list_prompts()
51
+
52
+ # Read a specific resource
53
+ config = await file_service.read_resource("file://config.json")
54
+
55
+ # Get a prompt template
56
+ prompt = await file_service.get_prompt("analysis_prompt", {"topic": "data"})
57
+
58
+ # Streaming tool call
59
+ async for chunk in file_service.call_tool_streaming("process_large_file", {"file": "big.txt"}):
60
+ print(chunk)
61
+
62
+ return "Processing complete"
63
+
64
+ The unified proxy provides all MCP protocol features while maintaining simple callable interface.
38
65
  """
39
66
 
40
- def __call__(self, arguments: dict[str, Any] = None) -> Any:
67
+ def __call__(self, arguments: Optional[dict[str, Any]] = None) -> Any:
41
68
  """
42
69
  Call the bound remote function.
43
70
 
@@ -45,11 +72,11 @@ class McpMeshAgent(Protocol):
45
72
  arguments: Arguments to pass to the remote function (optional)
46
73
 
47
74
  Returns:
48
- Result from the remote function call
75
+ Result from the remote function call (CallToolResult object)
49
76
  """
50
77
  ...
51
78
 
52
- def invoke(self, arguments: dict[str, Any] = None) -> Any:
79
+ def invoke(self, arguments: Optional[dict[str, Any]] = None) -> Any:
53
80
  """
54
81
  Explicitly invoke the bound remote function.
55
82
 
@@ -60,14 +87,65 @@ class McpMeshAgent(Protocol):
60
87
  arguments: Arguments to pass to the remote function (optional)
61
88
 
62
89
  Returns:
63
- Result from the remote function call
90
+ Result from the remote function call (CallToolResult object)
64
91
 
65
92
  Example:
66
- result = date_getter.invoke({"format": "ISO"})
67
- # Same as: result = date_getter({"format": "ISO"})
93
+ result = date_service.invoke({"format": "ISO"})
94
+ # Same as: result = date_service({"format": "ISO"})
68
95
  """
69
96
  ...
70
97
 
98
+ # Full MCP Protocol Methods - now available on all McpMeshAgent proxies
99
+ async def list_tools(self) -> list:
100
+ """List available tools from remote agent."""
101
+ ...
102
+
103
+ async def list_resources(self) -> list:
104
+ """List available resources from remote agent."""
105
+ ...
106
+
107
+ async def read_resource(self, uri: str) -> Any:
108
+ """Read resource contents from remote agent."""
109
+ ...
110
+
111
+ async def list_prompts(self) -> list:
112
+ """List available prompts from remote agent."""
113
+ ...
114
+
115
+ async def get_prompt(self, name: str, arguments: Optional[dict] = None) -> Any:
116
+ """Get prompt template from remote agent."""
117
+ ...
118
+
119
+ # Streaming Support using FastMCP's superior streaming capabilities
120
+ async def call_tool_streaming(
121
+ self, name: str, arguments: dict = None, progress_handler=None
122
+ ) -> AsyncIterator[Any]:
123
+ """
124
+ Call a tool with streaming response using FastMCP's streaming support.
125
+
126
+ Args:
127
+ name: Tool name to call
128
+ arguments: Tool arguments
129
+ progress_handler: Optional progress handler for streaming
130
+
131
+ Yields:
132
+ Streaming response chunks
133
+ """
134
+ ...
135
+
136
+ # Session Management using FastMCP's built-in session support
137
+ async def create_session(self) -> str:
138
+ """Create a new session and return session ID."""
139
+ ...
140
+
141
+ async def call_with_session(self, session_id: str, **kwargs) -> Any:
142
+ """Call tool with explicit session ID for stateful operations."""
143
+ ...
144
+
145
+ async def close_session(self, session_id: str) -> bool:
146
+ """Close session and cleanup session state."""
147
+ ...
148
+
71
149
  if PYDANTIC_AVAILABLE:
72
150
 
73
151
  @classmethod
@@ -104,47 +182,30 @@ class McpMeshAgent(Protocol):
104
182
 
105
183
  class McpAgent(Protocol):
106
184
  """
107
- Protocol for Full MCP Agent proxies with complete MCP protocol support.
108
-
109
- This agent type provides access to the complete MCP protocol including:
110
- - Tools (call, list)
111
- - Resources (read, list)
112
- - Prompts (get, list)
113
- - Streaming tool calls
114
-
115
- Usage Examples:
116
- @mesh.tool(dependencies=[{"capability": "file_service"}])
117
- async def process_files(file_service: McpAgent) -> str:
118
- # Vanilla MCP Protocol usage (100% compatible)
119
- tools = await file_service.list_tools()
120
- resources = await file_service.list_resources()
121
- prompts = await file_service.list_prompts()
122
-
123
- # Read a specific resource
124
- config = await file_service.read_resource("file://config.json")
125
-
126
- # Get a prompt template
127
- prompt = await file_service.get_prompt("analysis_prompt", {"topic": "data"})
185
+ DEPRECATED: Use McpMeshAgent instead.
128
186
 
129
- # Basic tool call (McpMeshAgent compatibility)
130
- result = file_service({"action": "process"})
187
+ This type has been unified with McpMeshAgent. All features previously exclusive
188
+ to McpAgent are now available in McpMeshAgent using FastMCP's superior client.
131
189
 
132
- # Streaming tool call (breakthrough feature)
133
- async for chunk in file_service.call_tool_streaming("process_large_file", {"file": "big.txt"}):
134
- print(chunk)
190
+ Migration:
191
+ # Old way (deprecated)
192
+ def process_files(file_service: McpAgent) -> str:
193
+ pass
135
194
 
136
- return "Processing complete"
195
+ # New way (recommended)
196
+ def process_files(file_service: McpMeshAgent) -> str:
197
+ pass
137
198
 
138
- This proxy provides full MCP protocol access while maintaining backward compatibility
139
- with the basic __call__ interface from McpMeshAgent.
199
+ McpMeshAgent now provides all MCP protocol features including streaming,
200
+ session management, and CallToolResult objects via FastMCP client.
140
201
  """
141
202
 
142
203
  # Basic compatibility with McpMeshAgent
143
- def __call__(self, arguments: dict[str, Any] | None = None) -> Any:
204
+ def __call__(self, arguments: Optional[dict[str, Any]] = None) -> Any:
144
205
  """Call the bound remote function (McpMeshAgent compatibility)."""
145
206
  ...
146
207
 
147
- def invoke(self, arguments: dict[str, Any] | None = None) -> Any:
208
+ def invoke(self, arguments: Optional[dict[str, Any]] = None) -> Any:
148
209
  """Explicitly invoke the bound remote function (McpMeshAgent compatibility)."""
149
210
  ...
150
211
 
@@ -165,7 +226,7 @@ class McpAgent(Protocol):
165
226
  """List available prompts from remote agent (vanilla MCP method)."""
166
227
  ...
167
228
 
168
- async def get_prompt(self, name: str, arguments: dict | None = None) -> Any:
229
+ async def get_prompt(self, name: str, arguments: Optional[dict] = None) -> Any:
169
230
  """Get prompt template from remote agent (vanilla MCP method)."""
170
231
  ...
171
232
 
File without changes