claude-agent-sdk 0.36.0 → 0.37.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +2 -2
- data/docs/client.md +26 -1
- data/docs/hooks-and-permissions.md +5 -3
- data/docs/mcp-servers.md +1 -2
- data/docs/sessions.md +81 -2
- data/docs/types.md +106 -4
- data/lib/claude_agent_sdk/cli_installer.rb +30 -3
- data/lib/claude_agent_sdk/command_builder.rb +109 -98
- data/lib/claude_agent_sdk/deprecation.rb +39 -0
- data/lib/claude_agent_sdk/fiber_boundary.rb +2 -0
- data/lib/claude_agent_sdk/instrumentation/otel.rb +15 -7
- data/lib/claude_agent_sdk/message_parser.rb +23 -9
- data/lib/claude_agent_sdk/observer.rb +2 -1
- data/lib/claude_agent_sdk/option_warnings.rb +2 -0
- data/lib/claude_agent_sdk/query.rb +50 -43
- data/lib/claude_agent_sdk/sdk_mcp_server.rb +22 -13
- data/lib/claude_agent_sdk/session_mutations.rb +20 -8
- data/lib/claude_agent_sdk/session_resume.rb +20 -11
- data/lib/claude_agent_sdk/session_store.rb +7 -3
- data/lib/claude_agent_sdk/session_summary.rb +4 -2
- data/lib/claude_agent_sdk/sessions.rb +8 -6
- data/lib/claude_agent_sdk/streaming.rb +1 -1
- data/lib/claude_agent_sdk/subprocess_cli_transport.rb +72 -40
- data/lib/claude_agent_sdk/testing/session_store_conformance.rb +14 -10
- data/lib/claude_agent_sdk/transcript_mirror_batcher.rb +2 -0
- data/lib/claude_agent_sdk/types/attributes.rb +271 -0
- data/lib/claude_agent_sdk/types/base.rb +320 -0
- data/lib/claude_agent_sdk/types/content_blocks.rb +57 -0
- data/lib/claude_agent_sdk/types/hooks.rb +640 -0
- data/lib/claude_agent_sdk/types/mcp.rb +232 -0
- data/lib/claude_agent_sdk/types/messages.rb +614 -0
- data/lib/claude_agent_sdk/types/option_values.rb +302 -0
- data/lib/claude_agent_sdk/types/options.rb +352 -0
- data/lib/claude_agent_sdk/types/permissions.rb +107 -0
- data/lib/claude_agent_sdk/types/sessions.rb +10 -0
- data/lib/claude_agent_sdk/types.rb +13 -2534
- data/lib/claude_agent_sdk/version.rb +1 -1
- data/lib/claude_agent_sdk.rb +51 -17
- metadata +11 -1
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base'
|
|
4
|
+
|
|
5
|
+
module ClaudeAgentSDK
|
|
6
|
+
# MCP status response types
|
|
7
|
+
|
|
8
|
+
# MCP server connection status values
|
|
9
|
+
MCP_SERVER_CONNECTION_STATUSES = %w[connected failed needs-auth pending disabled].freeze
|
|
10
|
+
|
|
11
|
+
# MCP server info (name and version)
|
|
12
|
+
class McpServerInfo < Type
|
|
13
|
+
attr_accessor :name, :version
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# MCP tool annotation hints
|
|
17
|
+
class McpToolAnnotations < Type
|
|
18
|
+
attr_accessor :read_only, :destructive, :open_world
|
|
19
|
+
|
|
20
|
+
# Backwards-compatible parse; returns nil for nil input.
|
|
21
|
+
def self.parse(data)
|
|
22
|
+
from_hash(data)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# MCP tool info (name, description, annotations)
|
|
27
|
+
class McpToolInfo < Type
|
|
28
|
+
attr_accessor :name, :description
|
|
29
|
+
attr_reader :annotations
|
|
30
|
+
|
|
31
|
+
def annotations=(value)
|
|
32
|
+
@annotations = value.is_a?(Hash) ? McpToolAnnotations.new(value) : value
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Backwards-compatible parse; returns nil for nil input.
|
|
36
|
+
def self.parse(data)
|
|
37
|
+
from_hash(data)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Output-only serializable version of McpSdkServerConfig (without live instance)
|
|
42
|
+
# Returned in MCP status responses
|
|
43
|
+
class McpSdkServerConfigStatus < Type
|
|
44
|
+
attr_accessor :name
|
|
45
|
+
attr_reader :type
|
|
46
|
+
|
|
47
|
+
def initialize(attributes = {})
|
|
48
|
+
super
|
|
49
|
+
@type = 'sdk'
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def to_h
|
|
53
|
+
{ type: @type, name: @name }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Claude.ai proxy MCP server config
|
|
58
|
+
# Output-only type that appears in status responses for servers proxied through Claude.ai
|
|
59
|
+
class McpClaudeAIProxyServerConfig < Type
|
|
60
|
+
attr_accessor :url, :id
|
|
61
|
+
attr_reader :type
|
|
62
|
+
|
|
63
|
+
def initialize(attributes = {})
|
|
64
|
+
super
|
|
65
|
+
@type = 'claudeai-proxy'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def to_h
|
|
69
|
+
{ type: @type, url: @url, id: @id }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Status of a single MCP server connection
|
|
74
|
+
class McpServerStatus < Type
|
|
75
|
+
attr_accessor :name, :status, :error, :scope
|
|
76
|
+
attr_reader :server_info, :config, :tools
|
|
77
|
+
|
|
78
|
+
def server_info=(value)
|
|
79
|
+
@server_info = value.is_a?(Hash) ? McpServerInfo.new(value) : value
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def tools=(value)
|
|
83
|
+
@tools = if value.is_a?(Array)
|
|
84
|
+
value.map { |t| t.is_a?(Hash) ? McpToolInfo.new(t) : t }
|
|
85
|
+
else
|
|
86
|
+
value
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def config=(value)
|
|
91
|
+
@config = self.class.parse_config(value) || value
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Backwards-compatible parse; normalizes camelCase `serverInfo` and
|
|
95
|
+
# polymorphically builds the nested `config`.
|
|
96
|
+
def self.parse(data)
|
|
97
|
+
from_hash(data)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def self.parse_config(config)
|
|
101
|
+
return nil unless config.is_a?(Hash) && config[:type]
|
|
102
|
+
|
|
103
|
+
case config[:type]
|
|
104
|
+
when 'claudeai-proxy'
|
|
105
|
+
McpClaudeAIProxyServerConfig.new(url: config[:url], id: config[:id])
|
|
106
|
+
when 'sdk'
|
|
107
|
+
McpSdkServerConfigStatus.new(name: config[:name])
|
|
108
|
+
else
|
|
109
|
+
config
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Response from get_mcp_status containing all server statuses
|
|
115
|
+
class McpStatusResponse < Type
|
|
116
|
+
attr_reader :mcp_servers
|
|
117
|
+
|
|
118
|
+
def mcp_servers=(value)
|
|
119
|
+
@mcp_servers = if value.is_a?(Array)
|
|
120
|
+
value.map { |s| s.is_a?(Hash) ? McpServerStatus.new(s) : s }
|
|
121
|
+
else
|
|
122
|
+
value
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Backwards-compatible parse; returns nil for nil input.
|
|
127
|
+
def self.parse(data)
|
|
128
|
+
from_hash(data)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# MCP Server configurations
|
|
133
|
+
class McpStdioServerConfig < Type
|
|
134
|
+
include Type::OptionValue
|
|
135
|
+
|
|
136
|
+
strict_attributes
|
|
137
|
+
|
|
138
|
+
attr_accessor :command, :args, :env
|
|
139
|
+
attr_reader :type
|
|
140
|
+
|
|
141
|
+
inspect_filtered :env
|
|
142
|
+
|
|
143
|
+
def initialize(attributes = {})
|
|
144
|
+
super
|
|
145
|
+
@type = 'stdio'
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def to_h
|
|
149
|
+
result = { type: @type, command: @command }
|
|
150
|
+
result[:args] = @args if @args
|
|
151
|
+
result[:env] = @env if @env
|
|
152
|
+
result
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
class McpSSEServerConfig < Type
|
|
157
|
+
include Type::OptionValue
|
|
158
|
+
|
|
159
|
+
strict_attributes
|
|
160
|
+
|
|
161
|
+
attr_accessor :url, :headers
|
|
162
|
+
attr_reader :type
|
|
163
|
+
|
|
164
|
+
inspect_filtered :headers
|
|
165
|
+
|
|
166
|
+
def initialize(attributes = {})
|
|
167
|
+
super
|
|
168
|
+
@type = 'sse'
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def to_h
|
|
172
|
+
result = { type: @type, url: @url }
|
|
173
|
+
result[:headers] = @headers if @headers
|
|
174
|
+
result
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
class McpHttpServerConfig < Type
|
|
179
|
+
include Type::OptionValue
|
|
180
|
+
|
|
181
|
+
strict_attributes
|
|
182
|
+
|
|
183
|
+
attr_accessor :url, :headers
|
|
184
|
+
attr_reader :type
|
|
185
|
+
|
|
186
|
+
inspect_filtered :headers
|
|
187
|
+
|
|
188
|
+
def initialize(attributes = {})
|
|
189
|
+
super
|
|
190
|
+
@type = 'http'
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def to_h
|
|
194
|
+
result = { type: @type, url: @url }
|
|
195
|
+
result[:headers] = @headers if @headers
|
|
196
|
+
result
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
class McpSdkServerConfig < Type
|
|
201
|
+
include Type::OptionValue
|
|
202
|
+
|
|
203
|
+
strict_attributes
|
|
204
|
+
|
|
205
|
+
attr_accessor :name, :instance
|
|
206
|
+
attr_reader :type
|
|
207
|
+
|
|
208
|
+
def initialize(attributes = {})
|
|
209
|
+
super
|
|
210
|
+
@type = 'sdk'
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def to_h
|
|
214
|
+
{ type: @type, name: @name, instance: @instance }
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# SDK MCP Tool definition
|
|
219
|
+
class SdkMcpTool < Type
|
|
220
|
+
attr_accessor :name, :description, :input_schema, :handler, :annotations, :meta
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# SDK MCP Resource definition
|
|
224
|
+
class SdkMcpResource < Type
|
|
225
|
+
attr_accessor :uri, :name, :description, :mime_type, :reader
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# SDK MCP Prompt definition
|
|
229
|
+
class SdkMcpPrompt < Type
|
|
230
|
+
attr_accessor :name, :description, :arguments, :generator
|
|
231
|
+
end
|
|
232
|
+
end
|