|
6 | 6 | "encoding/json" |
7 | 7 | "fmt" |
8 | 8 | "log" |
| 9 | + "time" |
9 | 10 |
|
10 | 11 | "github.com/mark3labs/mcp-go/mcp" |
11 | 12 | "github.com/mark3labs/mcp-go/server" |
@@ -158,6 +159,19 @@ func (s *Server) ServeSSE(addr string) error { |
158 | 159 | return sseServer.Start(addr) |
159 | 160 | } |
160 | 161 |
|
| 162 | +// ServeHTTPStream starts the MCP server using Streamable HTTP transport |
| 163 | +func (s *Server) ServeHTTPStream(addr string) error { |
| 164 | + log.Printf("Starting OSV MCP server (Streamable HTTP) on %s", addr) |
| 165 | + |
| 166 | + httpSrv := server.NewStreamableHTTPServer(s.mcpServer, |
| 167 | + server.WithEndpointPath("/mcp"), |
| 168 | + server.WithStateLess(true), // stateless mode |
| 169 | + server.WithHeartbeatInterval(30*time.Second), |
| 170 | + ) |
| 171 | + |
| 172 | + return httpSrv.Start(addr) |
| 173 | +} |
| 174 | + |
161 | 175 | // handleQueryVulnerability handles the query_vulnerability tool |
162 | 176 | func (s *Server) handleQueryVulnerability(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
163 | 177 | commit := mcp.ParseString(request, "commit", "") |
@@ -213,9 +227,14 @@ func (s *Server) handleQueryVulnerability(ctx context.Context, request mcp.CallT |
213 | 227 |
|
214 | 228 | // handleQueryVulnerabilitiesBatch handles the query_vulnerabilities_batch tool |
215 | 229 | func (s *Server) handleQueryVulnerabilitiesBatch(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
216 | | - queriesRaw, ok := request.Params.Arguments["queries"].([]interface{}) |
| 230 | + args, ok := request.Params.Arguments.(map[string]interface{}) |
| 231 | + if !ok { |
| 232 | + return mcp.NewToolResultError("Invalid arguments format"), nil |
| 233 | + } |
| 234 | + |
| 235 | + queriesRaw, ok := args["queries"].([]interface{}) |
217 | 236 | if !ok { |
218 | | - return mcp.NewToolResultError("Invalid queries parameter"), nil |
| 237 | + return mcp.NewToolResultError("Invalid 'queries' parameter: must be array"), nil |
219 | 238 | } |
220 | 239 |
|
221 | 240 | // Convert queries to QueryRequest objects |
|
0 commit comments