forked from themanojdesai/python-a2a
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
227 lines (194 loc) · 5.58 KB
/
Copy path__init__.py
File metadata and controls
227 lines (194 loc) · 5.58 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
"""
Model Context Protocol (MCP) integration for python-a2a.
This module provides both the original MCP implementation and a new
specification-compliant implementation following the 2025-03-26 specification.
BACKWARD COMPATIBILITY:
All existing imports continue to work unchanged:
- MCPClient (original implementation)
- MCPEnabledAgent, FastMCP, etc.
NEW MCP 2025-03-26 API (Official Specification Terms):
For new projects or when upgrading, use:
- Client (official MCP client implementation)
- Server (official MCP server implementation)
- create_stdio_client() (convenience function)
Key Features of New Implementation:
- Full MCP 2025-03-26 specification compliance
- Proper JSON-RPC 2.0 implementation
- Standard stdio transport (as recommended by spec)
- Complete server with tools/resources/prompts
- Robust lifecycle management
- Production-ready for millions of users
- No monkey patching or proxy patterns
Migration Path:
Existing code: from python_a2a.mcp import MCPClient # Still works
New code: from python_a2a.mcp import Client, Server # Official MCP terms
"""
# Core MCP protocol implementation (new, spec-compliant)
from .protocol import (
MCPProtocolHandler,
MCPProtocolError,
JSONRPCRequest,
JSONRPCResponse,
JSONRPCError,
JSONRPCErrorCode,
MCPImplementationInfo,
MCPCapabilities,
MCPContent,
create_text_content,
create_image_content,
create_blob_content
)
# MCP Server implementation (new, spec-compliant)
from .server import (
MCPServer,
MCPServerHandler,
MCPTool,
MCPResource,
MCPPrompt
)
# MCP Connection and lifecycle management (new, spec-compliant)
from .connection import (
MCPConnection,
MCPConnectionState,
MCPMessageHandler
)
# Standard stdio transport (new, spec-compliant)
from .transports import (
StdioTransport,
ServerStdioTransport,
create_stdio_transport,
create_server_stdio_transport
)
# Backward compatibility: Keep original MCPClient as default
from .client import (
MCPClient, # Original client - maintains backward compatibility
MCPError,
MCPConnectionError,
MCPTimeoutError,
MCPToolError
)
# New implementation following MCP specification terminology
from .clients import (
MCPClient as Client,
MCPClientHandler,
create_stdio_client
)
from .server import (
MCPServer as Server,
MCPServerHandler
)
# Backward compatibility: Legacy agent
from .agent import MCPEnabledAgent
# Backward compatibility: FastMCP implementation
from .fastmcp import (
FastMCP,
MCPResponse,
text_response,
error_response,
image_response,
multi_content_response
)
# Server configuration and management
from .server_config import (
ServerConfig,
MCPServerRunner,
MCPServerManager,
create_github_config,
create_filesystem_config
)
# MCP providers for external servers (local only)
from .providers import (
GitHubMCPServer, BrowserbaseMCPServer, FilesystemMCPServer,
PuppeteerMCPServer, PlaywrightMCPServer
)
# Backward compatibility: Legacy integrations (DEPRECATED)
try:
from .integration import (
FastMCPAgent,
A2AMCPAgent
)
except ImportError:
# Integration module may not exist in all environments
FastMCPAgent = None
A2AMCPAgent = None
# Backward compatibility: Proxy functionality (DEPRECATED)
try:
from .proxy import create_proxy_server
except ImportError:
create_proxy_server = None
# Backward compatibility: Transport
try:
from .transport import create_fastapi_app
except ImportError:
create_fastapi_app = None
# Main API - use these for new code
# MCPClient is the primary client interface (from clients.py)
__all__ = [
# Backward compatibility (existing imports continue to work)
"MCPClient", # Original client implementation
"MCPEnabledAgent",
"FastMCP",
"MCPResponse",
"text_response",
"error_response",
"image_response",
"multi_content_response",
# Common error classes
"MCPError",
"MCPConnectionError",
"MCPTimeoutError",
"MCPToolError",
# New MCP 2025-03-26 API (Official Specification Terms)
"Server", # Official MCP server
"Client", # Official MCP client
"MCPConnection",
"StdioTransport",
"create_stdio_transport",
"create_server_stdio_transport",
"create_stdio_client",
# Core protocol classes
"MCPProtocolHandler",
"MCPImplementationInfo",
"MCPCapabilities",
"MCPContent",
"MCPConnectionState",
# Server components
"MCPServerHandler",
"MCPTool",
"MCPResource",
"MCPPrompt",
"MCPMessageHandler",
# Client components
"MCPClientHandler",
# Content creation helpers
"create_text_content",
"create_image_content",
"create_blob_content",
# Core errors and protocols
"MCPProtocolError",
"JSONRPCRequest",
"JSONRPCResponse",
"JSONRPCError",
"JSONRPCErrorCode",
# Server configuration and management
"ServerConfig",
"MCPServerRunner",
"MCPServerManager",
"create_github_config",
"create_filesystem_config",
# High-level MCP providers (local)
"GitHubMCPServer",
"BrowserbaseMCPServer",
"FilesystemMCPServer",
"PuppeteerMCPServer",
"PlaywrightMCPServer",
]
# Add conditional exports for backward compatibility
if FastMCPAgent is not None:
__all__.extend(["FastMCPAgent", "A2AMCPAgent"])
if create_proxy_server is not None:
__all__.append("create_proxy_server")
if create_fastapi_app is not None:
__all__.append("create_fastapi_app")
# Version info
__version__ = "2.0.0" # Major version bump for spec compliance