feat: add network mode for combined HTTP and SSE endpoints
Add new 'network' transport mode that serves both HTTP and SSE protocols on the same port with different URL paths: - HTTP endpoint: /mcp - SSE endpoint: /sse Changes: - Add network mode to operation/operation.go using http.ServeMux routing - Update cmd/cmd.go flag descriptions to include network option - Update README.md with network mode documentation and examples - Update config.json with network mode configuration examples The network mode allows clients to choose between HTTP or SSE protocols without requiring separate server instances or ports. This provides better resource utilization and simpler deployment. Backward compatibility maintained - all existing modes (stdio, http, sse) work unchanged. Based on v0.3.0 for clean upstream compatibility.
This commit is contained in:
@@ -21,13 +21,13 @@ func init() {
|
||||
&flagPkg.Mode,
|
||||
"t",
|
||||
"stdio",
|
||||
"Transport type (stdio, sse or http)",
|
||||
"Transport type (stdio, sse, http, or network)",
|
||||
)
|
||||
flag.StringVar(
|
||||
&flagPkg.Mode,
|
||||
"transport",
|
||||
"stdio",
|
||||
"Transport type (stdio, sse or http)",
|
||||
"Transport type (stdio, sse, http, or network)",
|
||||
)
|
||||
flag.StringVar(
|
||||
&host,
|
||||
|
||||
BIN
gitea-mcp-network
Executable file
BIN
gitea-mcp-network
Executable file
Binary file not shown.
BIN
gitea-mcp-v0.3.0
Executable file
BIN
gitea-mcp-v0.3.0
Executable file
Binary file not shown.
@@ -2,6 +2,7 @@ package operation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"gitea.com/gitea/gitea-mcp/operation/issue"
|
||||
"gitea.com/gitea/gitea-mcp/operation/pull"
|
||||
@@ -59,8 +60,21 @@ func Run() error {
|
||||
if err := httpServer.Start(fmt.Sprintf(":%d", flag.Port)); err != nil {
|
||||
return err
|
||||
}
|
||||
case "network":
|
||||
// Network mode: serve both HTTP and SSE on same port with different URLs
|
||||
streamableServer := server.NewStreamableHTTPServer(mcpServer)
|
||||
sseServer := server.NewSSEServer(mcpServer)
|
||||
|
||||
// Create custom HTTP mux
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/mcp", streamableServer)
|
||||
mux.Handle("/sse", sseServer)
|
||||
|
||||
// Start single HTTP server
|
||||
log.Infof("Gitea MCP server listening on :%d (/mcp, /sse)", flag.Port)
|
||||
return http.ListenAndServe(fmt.Sprintf(":%d", flag.Port), mux)
|
||||
default:
|
||||
return fmt.Errorf("invalid transport type: %s. Must be 'stdio', 'sse' or 'http'", flag.Mode)
|
||||
return fmt.Errorf("invalid transport type: %s. Must be 'stdio', 'sse', 'http' or 'network'", flag.Mode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user