Skip to content
Open
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
10 changes: 5 additions & 5 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/NP-compete/gomcp/internal/api"
"github.com/NP-compete/gomcp/internal/config"
"github.com/NP-compete/gomcp/internal/constants"
"github.com/NP-compete/gomcp/internal/logger"
"github.com/NP-compete/gomcp/internal/mcp"
"github.com/NP-compete/gomcp/internal/oauth"
Expand Down Expand Up @@ -111,9 +111,9 @@ func runHTTPTransport(cfg *config.Config) {
srv := &http.Server{
Addr: addr,
Handler: router,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 120 * time.Second,
ReadTimeout: constants.DefaultReadTimeout,
WriteTimeout: constants.DefaultWriteTimeout,
IdleTimeout: constants.DefaultIdleTimeout,
}

// Start server in a goroutine
Expand Down Expand Up @@ -143,7 +143,7 @@ func runHTTPTransport(cfg *config.Config) {
logger.Info("Received shutdown signal, shutting down gracefully...")

// Create shutdown context with timeout
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), constants.DefaultShutdownTimeout)
defer cancel()

// Shutdown HTTP server
Expand Down
4 changes: 2 additions & 2 deletions internal/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package api

import (
"net/http"
"time"

"github.com/NP-compete/gomcp/internal/config"
"github.com/NP-compete/gomcp/internal/constants"
"github.com/NP-compete/gomcp/internal/logger"
"github.com/NP-compete/gomcp/internal/mcp"
"github.com/NP-compete/gomcp/internal/middleware"
Expand Down Expand Up @@ -39,7 +39,7 @@ func NewRouter(cfg *config.Config, mcpServer *mcp.Server, oauthService *oauth.Se
r.Use(middleware.Recovery(*log)) // Recover from panics with logging
r.Use(middleware.LoggingMiddleware) // Log all requests
r.Use(chimiddleware.Compress(5)) // Compress responses
r.Use(chimiddleware.Timeout(60 * time.Second)) // Request timeout
r.Use(chimiddleware.Timeout(constants.DefaultRequestTimeout)) // Request timeout

// Apply session middleware
sessionSecret := cfg.GetSessionSecret()
Expand Down
46 changes: 46 additions & 0 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package constants

import "time"

const (
// HTTP Server Timeouts

// DefaultRequestTimeout is the maximum duration for processing a request
DefaultRequestTimeout = 60 * time.Second

// DefaultReadTimeout is the maximum duration for reading the request body
DefaultReadTimeout = 30 * time.Second

// DefaultWriteTimeout is the maximum duration for writing the response
DefaultWriteTimeout = 30 * time.Second

// DefaultIdleTimeout is the maximum duration for idle connections
DefaultIdleTimeout = 120 * time.Second

// DefaultShutdownTimeout is the maximum duration for graceful shutdown
DefaultShutdownTimeout = 30 * time.Second

// Pagination

// DefaultPageSize is the default number of items per page
DefaultPageSize = 10

// MaxPageSize is the maximum number of items per page
MaxPageSize = 100

// Long Operation Tool

// MinOperationSeconds is the minimum duration for long operation test tool
MinOperationSeconds = 1

// MaxOperationSeconds is the maximum duration for long operation test tool
MaxOperationSeconds = 60

// Rate Limiting (for future use)

// DefaultRateLimit is the default rate limit per minute
DefaultRateLimit = 100

// DefaultBurstSize is the default burst size for rate limiting
DefaultBurstSize = 20
)
9 changes: 5 additions & 4 deletions internal/tools/long_operation_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"time"

"github.com/NP-compete/gomcp/internal/constants"
"github.com/NP-compete/gomcp/internal/logger"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
Expand Down Expand Up @@ -49,11 +50,11 @@ func LongOperationSDK(
}

// Validate input
if input.Seconds < 1 {
input.Seconds = 1
if input.Seconds < constants.MinOperationSeconds {
input.Seconds = constants.MinOperationSeconds
}
if input.Seconds > 60 {
input.Seconds = 60
if input.Seconds > constants.MaxOperationSeconds {
input.Seconds = constants.MaxOperationSeconds
}
if input.Task == "" {
input.Task = "long operation"
Expand Down
5 changes: 3 additions & 2 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/NP-compete/gomcp/internal/api"
"github.com/NP-compete/gomcp/internal/config"
"github.com/NP-compete/gomcp/internal/constants"
"github.com/NP-compete/gomcp/internal/mcp"
)

Expand Down Expand Up @@ -123,8 +124,8 @@ func TestInitialize(t *testing.T) {
t.Error("Expected pagination.support to be true")
}

if pag["maxPageSize"] != float64(100) {
t.Errorf("Expected pagination.maxPageSize to be 100, got %v", pag["maxPageSize"])
if pag["maxPageSize"] != float64(constants.MaxPageSize) {
t.Errorf("Expected pagination.maxPageSize to be %d, got %v", constants.MaxPageSize, pag["maxPageSize"])
}

// Check logging
Expand Down