Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ The server can be configured using environment variables:
- Must be a valid integer between 0 and 65535
- If invalid or not set, the server will use port 8080

- `MCP_TRANSPORT_MODE`: The transport mode for the server (default: `sse`)
- Supported values: `sse`, `stream`
- If invalid or not set, the server will use SSE transport mode

Example:
```bash
# Run on port 3000
Expand Down
12 changes: 11 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/signal"
"strconv"
"strings"
"syscall"

"github.com/StacklokLabs/osv-mcp/pkg/mcp"
Expand Down Expand Up @@ -39,6 +40,10 @@ func main() {
// Parse command-line flags
addr := flag.String("addr", ":"+port, "Address to listen on")
flag.Parse()
mode := strings.ToLower(strings.TrimSpace(os.Getenv("MCP_TRANSPORT_MODE")))
if mode == "" {
mode = "sse" // Default to "sse" if MCP_TRANSPORT_MODE is not set
}

// Create OSV client
osvClient := osv.NewClient()
Expand All @@ -55,7 +60,12 @@ func main() {
// Start server in a goroutine
errChan := make(chan error, 1)
go func() {
errChan <- mcpServer.ServeSSE(*addr)
switch mode {
case "stream":
errChan <- mcpServer.ServeHTTPStream(*addr)
default:
errChan <- mcpServer.ServeSSE(*addr)
}
}()

// Wait for signal or error
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module github.com/StacklokLabs/osv-mcp
go 1.24.2

require (
github.com/mark3labs/mcp-go v0.28.0
github.com/mark3labs/mcp-go v0.32.0
github.com/stretchr/testify v1.10.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/cast v1.9.2 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mark3labs/mcp-go v0.28.0 h1:7yl4y5D1KYU2f/9Uxp7xfLIggfunHoESCRbrjcytcLM=
github.com/mark3labs/mcp-go v0.28.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
github.com/mark3labs/mcp-go v0.32.0 h1:fgwmbfL2gbd67obg57OfV2Dnrhs1HtSdlY/i5fn7MU8=
github.com/mark3labs/mcp-go v0.32.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spf13/cast v1.9.2 h1:SsGfm7M8QOFtEzumm7UZrZdLLquNdzFYfIbEXntcFbE=
github.com/spf13/cast v1.9.2/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
Expand Down
23 changes: 21 additions & 2 deletions pkg/mcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"log"
"time"

"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
Expand Down Expand Up @@ -158,6 +159,19 @@ func (s *Server) ServeSSE(addr string) error {
return sseServer.Start(addr)
}

// ServeHTTPStream starts the MCP server using Streamable HTTP transport
func (s *Server) ServeHTTPStream(addr string) error {
log.Printf("Starting OSV MCP server (Streamable HTTP) on %s", addr)

httpSrv := server.NewStreamableHTTPServer(s.mcpServer,
server.WithEndpointPath("/mcp"),
server.WithStateLess(true), // stateless mode
server.WithHeartbeatInterval(30*time.Second),
)

return httpSrv.Start(addr)
}

// handleQueryVulnerability handles the query_vulnerability tool
func (s *Server) handleQueryVulnerability(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
commit := mcp.ParseString(request, "commit", "")
Expand Down Expand Up @@ -213,9 +227,14 @@ func (s *Server) handleQueryVulnerability(ctx context.Context, request mcp.CallT

// handleQueryVulnerabilitiesBatch handles the query_vulnerabilities_batch tool
func (s *Server) handleQueryVulnerabilitiesBatch(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
queriesRaw, ok := request.Params.Arguments["queries"].([]interface{})
args, ok := request.Params.Arguments.(map[string]interface{})
if !ok {
return mcp.NewToolResultError("Invalid arguments format"), nil
}

queriesRaw, ok := args["queries"].([]interface{})
if !ok {
return mcp.NewToolResultError("Invalid queries parameter"), nil
return mcp.NewToolResultError("Invalid 'queries' parameter: must be array"), nil
}

// Convert queries to QueryRequest objects
Expand Down