stack-service-base 0.0.62 → 0.0.64
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f73b91212d7125c660258defabaa0f09540b66458f31222340109ee1b4e31354
|
|
4
|
+
data.tar.gz: 296d9f39dd8fac208801c5195141c2a29d134163ae20cc230f3baecc24380c2c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e5f0a35ad58b849f923bd0a9df6a794b1ab52964f51732c60649d3308e29cab3df691c9090e857b0d7d2037ece0cf6068faf1473eb276881fb1db3fbdec0d566
|
|
7
|
+
data.tar.gz: ea99bd368e07a109da81577522ca6a8071662b67b7cc198a4c78159a74c68ee81a68a11a0c601a46560706ecdc061679a6a512328b64372c8df21119aa334212
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require_relative 'mcp_processor'
|
|
2
|
+
require_relative 'mcp_tool_registry'
|
|
3
|
+
|
|
4
|
+
MCP_PROCESSOR = McpProcessor.new
|
|
5
|
+
|
|
6
|
+
module McpHelper
|
|
7
|
+
def self.included(base)
|
|
8
|
+
base.class_eval do
|
|
9
|
+
|
|
10
|
+
error McpProcessor::ParseError do |err|
|
|
11
|
+
status err.status
|
|
12
|
+
err.body
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
get '/mcp' do
|
|
16
|
+
content_type :json
|
|
17
|
+
MCP_PROCESSOR.root_endpoint
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
post '/mcp' do
|
|
21
|
+
content_type 'text/event-stream'
|
|
22
|
+
headers['Cache-Control'] = 'no-cache'
|
|
23
|
+
headers['X-Accel-Buffering'] = 'no'
|
|
24
|
+
headers['mcp-session-id'] = SecureRandom.uuid
|
|
25
|
+
request.body&.rewind
|
|
26
|
+
body = request.body.read.to_s
|
|
27
|
+
|
|
28
|
+
response_body =
|
|
29
|
+
begin
|
|
30
|
+
MCP_PROCESSOR.rpc_endpoint(body)
|
|
31
|
+
rescue McpProcessor::ParseError => e
|
|
32
|
+
status e.status
|
|
33
|
+
e.body
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
LOGGER.debug "request body: #{body}"
|
|
37
|
+
LOGGER.debug "response body: #{response_body}"
|
|
38
|
+
|
|
39
|
+
stream true do |s|
|
|
40
|
+
s.callback { LOGGER.debug "stream closed: #{s}" }
|
|
41
|
+
s << "event: message\ndata: #{response_body}\n\n"
|
|
42
|
+
s.close
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -115,6 +115,12 @@ class McpProcessor
|
|
|
115
115
|
name = params["name"]
|
|
116
116
|
arguments = params["arguments"] || {}
|
|
117
117
|
tool = ToolRegistry.fetch(name) || rpc_error!(-32601, "Unknown tool #{name}")
|
|
118
|
-
tool.call(arguments)
|
|
118
|
+
response = tool.call(arguments)
|
|
119
|
+
{
|
|
120
|
+
content: [
|
|
121
|
+
{ "type": "text", "text": response.is_a?(String) ? response : response.to_json }
|
|
122
|
+
],
|
|
123
|
+
isError: false
|
|
124
|
+
}
|
|
119
125
|
end
|
|
120
126
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stack-service-base
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.64
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Artyom B
|
|
@@ -401,6 +401,7 @@ files:
|
|
|
401
401
|
- lib/stack-service-base/examples/mcp_config.ru
|
|
402
402
|
- lib/stack-service-base/fiber_pool.rb
|
|
403
403
|
- lib/stack-service-base/logging.rb
|
|
404
|
+
- lib/stack-service-base/mcp_helper.rb
|
|
404
405
|
- lib/stack-service-base/mcp_processor.rb
|
|
405
406
|
- lib/stack-service-base/mcp_tool_registry.rb
|
|
406
407
|
- lib/stack-service-base/nats_patch_1.rb
|