ask-mcp 0.4.5 → 0.5.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 +69 -0
- data/lib/ask/mcp/adapters/tool_server.rb +27 -0
- data/lib/ask/mcp/client.rb +46 -3
- data/lib/ask/mcp/server/core.rb +372 -0
- data/lib/ask/mcp/server/http.rb +344 -0
- data/lib/ask/mcp/server/stdio.rb +16 -292
- data/lib/ask/mcp/server.rb +18 -0
- data/lib/ask/mcp/transport/streamable_http.rb +27 -15
- data/lib/ask/mcp/version.rb +1 -1
- metadata +4 -2
data/lib/ask/mcp/server.rb
CHANGED
|
@@ -54,9 +54,27 @@ module Ask
|
|
|
54
54
|
resources: resources, prompts: prompts,
|
|
55
55
|
resource_templates: resource_templates, debug: debug).start
|
|
56
56
|
end
|
|
57
|
+
|
|
58
|
+
# Build a Rack application serving MCP over the stateless Streamable
|
|
59
|
+
# HTTP transport (2026-07-28). Mount it wherever Rack runs:
|
|
60
|
+
#
|
|
61
|
+
# mount Ask::MCP::Server.rack_app(name: "anychat", tools: [...]) => "/mcp"
|
|
62
|
+
#
|
|
63
|
+
# Accepts the same tool/resource/prompt options as .start_stdio, plus:
|
|
64
|
+
#
|
|
65
|
+
# @param authenticate [#call, nil] receives the Rack env per request and
|
|
66
|
+
# returns the caller's identity; a nil return answers 401
|
|
67
|
+
# @param context [#call, nil] derives the value passed to a callable
|
|
68
|
+
# `tools` when no `authenticate` is given (defaults to the Rack env)
|
|
69
|
+
# @return [Server::HTTP] a Rack application
|
|
70
|
+
def self.rack_app(**options)
|
|
71
|
+
HTTP.new(**options)
|
|
72
|
+
end
|
|
57
73
|
end
|
|
58
74
|
end
|
|
59
75
|
end
|
|
60
76
|
|
|
61
77
|
# Load Server subclasses after the Server class is defined
|
|
78
|
+
require_relative "server/core"
|
|
62
79
|
require_relative "server/stdio"
|
|
80
|
+
require_relative "server/http"
|
|
@@ -138,26 +138,38 @@ module Ask
|
|
|
138
138
|
|
|
139
139
|
def handle_response(response)
|
|
140
140
|
status = response.status
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return response
|
|
144
|
-
end
|
|
145
|
-
unless status == 200
|
|
146
|
-
raise ConnectionError, "HTTP #{status}: #{response.body.to_s[0..200]}"
|
|
147
|
-
end
|
|
141
|
+
# Notification accepted, no body.
|
|
142
|
+
return response if status == 202
|
|
148
143
|
|
|
149
144
|
content_type = response.headers["content-type"].to_s
|
|
150
|
-
if content_type.include?("text/event-stream")
|
|
145
|
+
if status == 200 && content_type.include?("text/event-stream")
|
|
151
146
|
read_sse_stream(response)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
147
|
+
return response
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
body = response.body.to_s
|
|
151
|
+
# A server may carry a JSON-RPC error on a non-200 status — 400 for a
|
|
152
|
+
# header mismatch or an unsupported protocol version, 404 for a
|
|
153
|
+
# method it does not implement. That is a response, not a transport
|
|
154
|
+
# failure, so it goes to the message handlers where the pending
|
|
155
|
+
# request can pick it up.
|
|
156
|
+
message = parse_message(body)
|
|
157
|
+
if message
|
|
158
|
+
@message_handlers.each { |handler| handler.call(message) }
|
|
159
|
+
return response
|
|
158
160
|
end
|
|
159
161
|
|
|
160
|
-
response
|
|
162
|
+
return response if status == 200
|
|
163
|
+
|
|
164
|
+
raise ConnectionError, "HTTP #{status}: #{body[0..200]}"
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def parse_message(body)
|
|
168
|
+
return nil if body.empty?
|
|
169
|
+
|
|
170
|
+
Native::Messages::Parser.parse(body)
|
|
171
|
+
rescue JSON::ParserError
|
|
172
|
+
nil
|
|
161
173
|
end
|
|
162
174
|
|
|
163
175
|
# Read an SSE stream, delivering each `data:` payload as a parsed
|
data/lib/ask/mcp/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ask-mcp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kaka Ruto
|
|
@@ -119,6 +119,8 @@ files:
|
|
|
119
119
|
- lib/ask/mcp/prompt.rb
|
|
120
120
|
- lib/ask/mcp/resource.rb
|
|
121
121
|
- lib/ask/mcp/server.rb
|
|
122
|
+
- lib/ask/mcp/server/core.rb
|
|
123
|
+
- lib/ask/mcp/server/http.rb
|
|
122
124
|
- lib/ask/mcp/server/stdio.rb
|
|
123
125
|
- lib/ask/mcp/tool.rb
|
|
124
126
|
- lib/ask/mcp/trace_context.rb
|
|
@@ -149,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
149
151
|
- !ruby/object:Gem::Version
|
|
150
152
|
version: '0'
|
|
151
153
|
requirements: []
|
|
152
|
-
rubygems_version: 4.0.
|
|
154
|
+
rubygems_version: 4.0.18
|
|
153
155
|
specification_version: 4
|
|
154
156
|
summary: Model Context Protocol (MCP) client and server for Ruby
|
|
155
157
|
test_files: []
|