ask-mcp 0.4.6 → 0.6.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,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Ask
2
4
  module MCP
3
- VERSION = "0.4.6"
5
+ VERSION = "0.6.0"
4
6
  end
5
7
  end
data/lib/ask/mcp.rb CHANGED
@@ -37,6 +37,7 @@ module Ask
37
37
 
38
38
  module Auth
39
39
  autoload :OAuth, "ask/mcp/auth/oauth"
40
+ autoload :Connect, "ask/mcp/auth/connect"
40
41
  autoload :Token, "ask/mcp/auth/token"
41
42
  autoload :ClientIdMetadataDocument, "ask/mcp/auth/client_id_metadata_document"
42
43
  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.6
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto
@@ -112,6 +112,7 @@ files:
112
112
  - lib/ask/mcp/adapters/ask_tool.rb
113
113
  - lib/ask/mcp/adapters/tool_server.rb
114
114
  - lib/ask/mcp/auth/client_id_metadata_document.rb
115
+ - lib/ask/mcp/auth/connect.rb
115
116
  - lib/ask/mcp/auth/oauth.rb
116
117
  - lib/ask/mcp/auth/token.rb
117
118
  - lib/ask/mcp/client.rb
@@ -119,6 +120,8 @@ files:
119
120
  - lib/ask/mcp/prompt.rb
120
121
  - lib/ask/mcp/resource.rb
121
122
  - lib/ask/mcp/server.rb
123
+ - lib/ask/mcp/server/core.rb
124
+ - lib/ask/mcp/server/http.rb
122
125
  - lib/ask/mcp/server/stdio.rb
123
126
  - lib/ask/mcp/tool.rb
124
127
  - lib/ask/mcp/trace_context.rb