acp-sdk 0.0.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.
- acp/__init__.py +138 -0
- acp/cli/__init__.py +6 -0
- acp/cli/claude.py +139 -0
- acp/cli/cli.py +471 -0
- acp/client/__init__.py +0 -0
- acp/client/__main__.py +79 -0
- acp/client/session.py +372 -0
- acp/client/sse.py +142 -0
- acp/client/stdio.py +153 -0
- acp/py.typed +0 -0
- acp/server/__init__.py +3 -0
- acp/server/__main__.py +50 -0
- acp/server/highlevel/__init__.py +9 -0
- acp/server/highlevel/agents/__init__.py +5 -0
- acp/server/highlevel/agents/agent_manager.py +110 -0
- acp/server/highlevel/agents/base.py +22 -0
- acp/server/highlevel/agents/templates.py +23 -0
- acp/server/highlevel/context.py +185 -0
- acp/server/highlevel/exceptions.py +25 -0
- acp/server/highlevel/prompts/__init__.py +4 -0
- acp/server/highlevel/prompts/base.py +167 -0
- acp/server/highlevel/prompts/manager.py +50 -0
- acp/server/highlevel/prompts/prompt_manager.py +33 -0
- acp/server/highlevel/resources/__init__.py +23 -0
- acp/server/highlevel/resources/base.py +48 -0
- acp/server/highlevel/resources/resource_manager.py +94 -0
- acp/server/highlevel/resources/templates.py +80 -0
- acp/server/highlevel/resources/types.py +185 -0
- acp/server/highlevel/server.py +704 -0
- acp/server/highlevel/tools/__init__.py +4 -0
- acp/server/highlevel/tools/base.py +83 -0
- acp/server/highlevel/tools/tool_manager.py +53 -0
- acp/server/highlevel/utilities/__init__.py +1 -0
- acp/server/highlevel/utilities/func_metadata.py +210 -0
- acp/server/highlevel/utilities/logging.py +43 -0
- acp/server/highlevel/utilities/types.py +54 -0
- acp/server/lowlevel/__init__.py +3 -0
- acp/server/lowlevel/helper_types.py +9 -0
- acp/server/lowlevel/server.py +628 -0
- acp/server/models.py +17 -0
- acp/server/session.py +315 -0
- acp/server/sse.py +175 -0
- acp/server/stdio.py +83 -0
- acp/server/websocket.py +61 -0
- acp/shared/__init__.py +0 -0
- acp/shared/context.py +14 -0
- acp/shared/exceptions.py +14 -0
- acp/shared/memory.py +87 -0
- acp/shared/progress.py +40 -0
- acp/shared/session.py +409 -0
- acp/shared/version.py +3 -0
- acp/types.py +1258 -0
- acp_sdk-0.0.1.dist-info/METADATA +46 -0
- acp_sdk-0.0.1.dist-info/RECORD +57 -0
- acp_sdk-0.0.1.dist-info/WHEEL +4 -0
- acp_sdk-0.0.1.dist-info/entry_points.txt +2 -0
- acp_sdk-0.0.1.dist-info/licenses/LICENSE +22 -0
acp/__init__.py
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
from .client.session import ClientSession
|
2
|
+
from .client.stdio import StdioServerParameters, stdio_client
|
3
|
+
from .server.session import ServerSession
|
4
|
+
from .server.stdio import stdio_server
|
5
|
+
from .shared.exceptions import McpError
|
6
|
+
from .types import (
|
7
|
+
Agent,
|
8
|
+
AgentTemplate,
|
9
|
+
CallToolRequest,
|
10
|
+
ClientCapabilities,
|
11
|
+
ClientNotification,
|
12
|
+
ClientRequest,
|
13
|
+
ClientResult,
|
14
|
+
CompleteRequest,
|
15
|
+
CreateAgentRequest,
|
16
|
+
CreateAgentResult,
|
17
|
+
CreateMessageRequest,
|
18
|
+
CreateMessageResult,
|
19
|
+
DestroyAgentRequest,
|
20
|
+
DestroyAgentResult,
|
21
|
+
ErrorData,
|
22
|
+
GetPromptRequest,
|
23
|
+
GetPromptResult,
|
24
|
+
Implementation,
|
25
|
+
IncludeContext,
|
26
|
+
InitializedNotification,
|
27
|
+
InitializeRequest,
|
28
|
+
InitializeResult,
|
29
|
+
JSONRPCError,
|
30
|
+
JSONRPCRequest,
|
31
|
+
JSONRPCResponse,
|
32
|
+
ListAgentsRequest,
|
33
|
+
ListAgentsResult,
|
34
|
+
ListAgentTemplatesRequest,
|
35
|
+
ListAgentTemplatesResult,
|
36
|
+
ListPromptsRequest,
|
37
|
+
ListPromptsResult,
|
38
|
+
ListResourcesRequest,
|
39
|
+
ListResourcesResult,
|
40
|
+
ListToolsResult,
|
41
|
+
LoggingLevel,
|
42
|
+
LoggingMessageNotification,
|
43
|
+
Notification,
|
44
|
+
PingRequest,
|
45
|
+
ProgressNotification,
|
46
|
+
PromptsCapability,
|
47
|
+
ReadResourceRequest,
|
48
|
+
ReadResourceResult,
|
49
|
+
Resource,
|
50
|
+
ResourcesCapability,
|
51
|
+
ResourceUpdatedNotification,
|
52
|
+
RootsCapability,
|
53
|
+
RunAgentRequest,
|
54
|
+
RunAgentResult,
|
55
|
+
SamplingMessage,
|
56
|
+
ServerCapabilities,
|
57
|
+
ServerNotification,
|
58
|
+
ServerRequest,
|
59
|
+
ServerResult,
|
60
|
+
SetLevelRequest,
|
61
|
+
StopReason,
|
62
|
+
SubscribeRequest,
|
63
|
+
Tool,
|
64
|
+
ToolsCapability,
|
65
|
+
UnsubscribeRequest,
|
66
|
+
)
|
67
|
+
from .types import (
|
68
|
+
Role as SamplingRole,
|
69
|
+
)
|
70
|
+
|
71
|
+
__all__ = [
|
72
|
+
"CallToolRequest",
|
73
|
+
"ClientCapabilities",
|
74
|
+
"ClientNotification",
|
75
|
+
"ClientRequest",
|
76
|
+
"ClientResult",
|
77
|
+
"ClientSession",
|
78
|
+
"CreateMessageRequest",
|
79
|
+
"CreateMessageResult",
|
80
|
+
"ErrorData",
|
81
|
+
"GetPromptRequest",
|
82
|
+
"GetPromptResult",
|
83
|
+
"Implementation",
|
84
|
+
"IncludeContext",
|
85
|
+
"InitializeRequest",
|
86
|
+
"InitializeResult",
|
87
|
+
"InitializedNotification",
|
88
|
+
"JSONRPCError",
|
89
|
+
"JSONRPCRequest",
|
90
|
+
"ListPromptsRequest",
|
91
|
+
"ListPromptsResult",
|
92
|
+
"ListResourcesRequest",
|
93
|
+
"ListResourcesResult",
|
94
|
+
"ListToolsResult",
|
95
|
+
"LoggingLevel",
|
96
|
+
"LoggingMessageNotification",
|
97
|
+
"McpError",
|
98
|
+
"Notification",
|
99
|
+
"PingRequest",
|
100
|
+
"ProgressNotification",
|
101
|
+
"PromptsCapability",
|
102
|
+
"ReadResourceRequest",
|
103
|
+
"ReadResourceResult",
|
104
|
+
"ResourcesCapability",
|
105
|
+
"ResourceUpdatedNotification",
|
106
|
+
"Resource",
|
107
|
+
"RootsCapability",
|
108
|
+
"SamplingMessage",
|
109
|
+
"SamplingRole",
|
110
|
+
"ServerCapabilities",
|
111
|
+
"ServerNotification",
|
112
|
+
"ServerRequest",
|
113
|
+
"ServerResult",
|
114
|
+
"ServerSession",
|
115
|
+
"SetLevelRequest",
|
116
|
+
"StdioServerParameters",
|
117
|
+
"StopReason",
|
118
|
+
"SubscribeRequest",
|
119
|
+
"Tool",
|
120
|
+
"ToolsCapability",
|
121
|
+
"UnsubscribeRequest",
|
122
|
+
"stdio_client",
|
123
|
+
"stdio_server",
|
124
|
+
"CompleteRequest",
|
125
|
+
"JSONRPCResponse",
|
126
|
+
"AgentTemplate",
|
127
|
+
"ListAgentTemplatesRequest",
|
128
|
+
"ListAgentTemplatesResult",
|
129
|
+
"Agent",
|
130
|
+
"ListAgentsRequest",
|
131
|
+
"ListAgentsResult",
|
132
|
+
"CreateAgentRequest",
|
133
|
+
"CreateAgentResult",
|
134
|
+
"DestroyAgentRequest",
|
135
|
+
"DestroyAgentResult",
|
136
|
+
"RunAgentRequest",
|
137
|
+
"RunAgentResult",
|
138
|
+
]
|
acp/cli/__init__.py
ADDED
acp/cli/claude.py
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
"""Claude app integration utilities."""
|
2
|
+
|
3
|
+
import json
|
4
|
+
import sys
|
5
|
+
from pathlib import Path
|
6
|
+
|
7
|
+
from acp.server.highlevel.utilities.logging import get_logger
|
8
|
+
|
9
|
+
logger = get_logger(__name__)
|
10
|
+
|
11
|
+
MCP_PACKAGE = "acp[cli]"
|
12
|
+
|
13
|
+
|
14
|
+
def get_claude_config_path() -> Path | None:
|
15
|
+
"""Get the Claude config directory based on platform."""
|
16
|
+
if sys.platform == "win32":
|
17
|
+
path = Path(Path.home(), "AppData", "Roaming", "Claude")
|
18
|
+
elif sys.platform == "darwin":
|
19
|
+
path = Path(Path.home(), "Library", "Application Support", "Claude")
|
20
|
+
else:
|
21
|
+
return None
|
22
|
+
|
23
|
+
if path.exists():
|
24
|
+
return path
|
25
|
+
return None
|
26
|
+
|
27
|
+
|
28
|
+
def update_claude_config(
|
29
|
+
file_spec: str,
|
30
|
+
server_name: str,
|
31
|
+
*,
|
32
|
+
with_editable: Path | None = None,
|
33
|
+
with_packages: list[str] | None = None,
|
34
|
+
env_vars: dict[str, str] | None = None,
|
35
|
+
) -> bool:
|
36
|
+
"""Add or update a FastMCP server in Claude's configuration.
|
37
|
+
|
38
|
+
Args:
|
39
|
+
file_spec: Path to the server file, optionally with :object suffix
|
40
|
+
server_name: Name for the server in Claude's config
|
41
|
+
with_editable: Optional directory to install in editable mode
|
42
|
+
with_packages: Optional list of additional packages to install
|
43
|
+
env_vars: Optional dictionary of environment variables. These are merged with
|
44
|
+
any existing variables, with new values taking precedence.
|
45
|
+
|
46
|
+
Raises:
|
47
|
+
RuntimeError: If Claude Desktop's config directory is not found, indicating
|
48
|
+
Claude Desktop may not be installed or properly set up.
|
49
|
+
"""
|
50
|
+
config_dir = get_claude_config_path()
|
51
|
+
if not config_dir:
|
52
|
+
raise RuntimeError(
|
53
|
+
"Claude Desktop config directory not found. Please ensure Claude Desktop"
|
54
|
+
" is installed and has been run at least once to initialize its config."
|
55
|
+
)
|
56
|
+
|
57
|
+
config_file = config_dir / "claude_desktop_config.json"
|
58
|
+
if not config_file.exists():
|
59
|
+
try:
|
60
|
+
config_file.write_text("{}")
|
61
|
+
except Exception as e:
|
62
|
+
logger.error(
|
63
|
+
"Failed to create Claude config file",
|
64
|
+
extra={
|
65
|
+
"error": str(e),
|
66
|
+
"config_file": str(config_file),
|
67
|
+
},
|
68
|
+
)
|
69
|
+
return False
|
70
|
+
|
71
|
+
try:
|
72
|
+
config = json.loads(config_file.read_text())
|
73
|
+
if "mcpServers" not in config:
|
74
|
+
config["mcpServers"] = {}
|
75
|
+
|
76
|
+
# Always preserve existing env vars and merge with new ones
|
77
|
+
if (
|
78
|
+
server_name in config["mcpServers"]
|
79
|
+
and "env" in config["mcpServers"][server_name]
|
80
|
+
):
|
81
|
+
existing_env = config["mcpServers"][server_name]["env"]
|
82
|
+
if env_vars:
|
83
|
+
# New vars take precedence over existing ones
|
84
|
+
env_vars = {**existing_env, **env_vars}
|
85
|
+
else:
|
86
|
+
env_vars = existing_env
|
87
|
+
|
88
|
+
# Build uv run command
|
89
|
+
args = ["run"]
|
90
|
+
|
91
|
+
# Collect all packages in a set to deduplicate
|
92
|
+
packages = {MCP_PACKAGE}
|
93
|
+
if with_packages:
|
94
|
+
packages.update(pkg for pkg in with_packages if pkg)
|
95
|
+
|
96
|
+
# Add all packages with --with
|
97
|
+
for pkg in sorted(packages):
|
98
|
+
args.extend(["--with", pkg])
|
99
|
+
|
100
|
+
if with_editable:
|
101
|
+
args.extend(["--with-editable", str(with_editable)])
|
102
|
+
|
103
|
+
# Convert file path to absolute before adding to command
|
104
|
+
# Split off any :object suffix first
|
105
|
+
if ":" in file_spec:
|
106
|
+
file_path, server_object = file_spec.rsplit(":", 1)
|
107
|
+
file_spec = f"{Path(file_path).resolve()}:{server_object}"
|
108
|
+
else:
|
109
|
+
file_spec = str(Path(file_spec).resolve())
|
110
|
+
|
111
|
+
# Add fastmcp run command
|
112
|
+
args.extend(["acp", "run", file_spec])
|
113
|
+
|
114
|
+
server_config = {
|
115
|
+
"command": "uv",
|
116
|
+
"args": args,
|
117
|
+
}
|
118
|
+
|
119
|
+
# Add environment variables if specified
|
120
|
+
if env_vars:
|
121
|
+
server_config["env"] = env_vars
|
122
|
+
|
123
|
+
config["mcpServers"][server_name] = server_config
|
124
|
+
|
125
|
+
config_file.write_text(json.dumps(config, indent=2))
|
126
|
+
logger.info(
|
127
|
+
f"Added server '{server_name}' to Claude config",
|
128
|
+
extra={"config_file": str(config_file)},
|
129
|
+
)
|
130
|
+
return True
|
131
|
+
except Exception as e:
|
132
|
+
logger.error(
|
133
|
+
"Failed to update Claude config",
|
134
|
+
extra={
|
135
|
+
"error": str(e),
|
136
|
+
"config_file": str(config_file),
|
137
|
+
},
|
138
|
+
)
|
139
|
+
return False
|