Skip to content

Commit 449bf26

Browse files
Copilotlpcox
andcommitted
Format code and add example configuration for payload threshold
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
1 parent b38a961 commit 449bf26

4 files changed

Lines changed: 425 additions & 372 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Example MCP Gateway Configuration with Payload Size Threshold
2+
# This demonstrates the configurable payload size threshold feature
3+
4+
[gateway]
5+
port = 3000
6+
api_key = "your-api-key-here"
7+
8+
# Payload directory for storing large tool responses
9+
# Default: /tmp/jq-payloads
10+
payload_dir = "/tmp/jq-payloads"
11+
12+
# Payload size threshold (in bytes) for storing responses to disk
13+
# Payloads LARGER than this threshold are stored to disk and return metadata
14+
# Payloads SMALLER than or equal to this threshold are returned inline
15+
# Default: 1024 bytes (1KB)
16+
#
17+
# Examples:
18+
# payload_size_threshold = 1024 # 1KB - default, good for most use cases
19+
# payload_size_threshold = 512 # 512 bytes - more aggressive file storage
20+
# payload_size_threshold = 2048 # 2KB - fewer files, more inline responses
21+
# payload_size_threshold = 10240 # 10KB - minimal file storage
22+
payload_size_threshold = 1024
23+
24+
[servers.github]
25+
command = "docker"
26+
args = ["run", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", "-i", "ghcr.io/github/github-mcp-server:latest"]
27+
28+
[servers.filesystem]
29+
command = "docker"
30+
args = ["run", "--rm", "-i", "ghcr.io/github/filesystem-mcp-server:latest"]
31+
32+
# How it works:
33+
#
34+
# 1. Tool returns response data
35+
# 2. Middleware marshals data to JSON
36+
# 3. If JSON size <= payload_size_threshold:
37+
# - Return response inline (no file storage)
38+
# - Original data preserved
39+
# 4. If JSON size > payload_size_threshold:
40+
# - Save full payload to {payload_dir}/{sessionID}/{queryID}/payload.json
41+
# - Return metadata response with:
42+
# * queryID: unique query identifier
43+
# * payloadPath: full path to saved file
44+
# * preview: first 500 characters
45+
# * schema: jq-inferred schema of the data
46+
# * originalSize: size in bytes
47+
# * truncated: whether preview was truncated
48+
#
49+
# Benefits:
50+
# - Small responses (errors, status messages, simple data) are fast and inline
51+
# - Large responses (file contents, lists, search results) are saved to disk
52+
# - Clients can access full payloads via filesystem when needed
53+
# - Reduces memory pressure and network overhead

internal/difc/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func NewAgentRegistryWithDefaults(defaultSecrecy []Tag, defaultIntegrity []Tag)
142142
// GetOrCreate gets an existing agent or creates a new one with default labels
143143
func (r *AgentRegistry) GetOrCreate(agentID string) *AgentLabels {
144144
logAgent.Printf("GetOrCreate called for agentID=%s", agentID)
145-
145+
146146
// Try to get existing agent first (read lock)
147147
r.mu.RLock()
148148
if labels, ok := r.agents[agentID]; ok {

0 commit comments

Comments
 (0)