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.
@@ -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
- if status == 202
142
- # Notification accepted, no body.
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
- else
153
- body = response.body.to_s
154
- if body && !body.empty?
155
- message = Native::Messages::Parser.parse(body)
156
- @message_handlers.each { |handler| handler.call(message) }
157
- end
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
@@ -1,5 +1,5 @@
1
1
  module Ask
2
2
  module MCP
3
- VERSION = "0.4.5"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
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.5
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.3
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: []