adds optional stateless configuration (#222)
* optional statelessness * Update config.ts * Update docker-compose.yml * Update documentation --------- Co-authored-by: Harold Spencer Jr. <hspencer@brave.com>
This commit is contained in:
1 parent
1971bc05d6
commit
dd16a2e084
5 files changed
+44
-7
No files matched your search
@@ -114,11 +114,12 @@ The server supports the following environment variables:
|
|||||||
|
|
||||||
- `BRAVE_API_KEY`: Your Brave Search API key (required)
|
- `BRAVE_API_KEY`: Your Brave Search API key (required)
|
||||||
- `BRAVE_MCP_TRANSPORT`: Transport mode ("http" or "stdio", default: "stdio")
|
- `BRAVE_MCP_TRANSPORT`: Transport mode ("http" or "stdio", default: "stdio")
|
||||||
- `BRAVE_MCP_PORT`: HTTP server port (default: 8080)
|
- `BRAVE_MCP_PORT`: HTTP server port (default: 8000)
|
||||||
- `BRAVE_MCP_HOST`: HTTP server host (default: "0.0.0.0")
|
- `BRAVE_MCP_HOST`: HTTP server host (default: "0.0.0.0")
|
||||||
- `BRAVE_MCP_LOG_LEVEL`: Desired logging level("debug", "info", "notice", "warning", "error", "critical", "alert", or "emergency", default: "info")
|
- `BRAVE_MCP_LOG_LEVEL`: Desired logging level("debug", "info", "notice", "warning", "error", "critical", "alert", or "emergency", default: "info")
|
||||||
- `BRAVE_MCP_ENABLED_TOOLS`: When used, specifies a whitelist for supported tools
|
- `BRAVE_MCP_ENABLED_TOOLS`: When used, specifies a whitelist for supported tools
|
||||||
- `BRAVE_MCP_DISABLED_TOOLS`: When used, specifies a blacklist for supported tools
|
- `BRAVE_MCP_DISABLED_TOOLS`: When used, specifies a blacklist for supported tools
|
||||||
|
- `BRAVE_MCP_STATELESS`: HTTP stateless mode (default: "true"). When running on Amazon Bedrock Agentcore, set to "true".
|
||||||
|
|
||||||
### Command Line Options
|
### Command Line Options
|
||||||
|
|
||||||
@@ -133,6 +134,7 @@ Options:
|
|||||||
--logging-level <string> Desired logging level (one of _debug_, _info_, _notice_, _warning_, _error_, _critical_, _alert_, or _emergency_)
|
--logging-level <string> Desired logging level (one of _debug_, _info_, _notice_, _warning_, _error_, _critical_, _alert_, or _emergency_)
|
||||||
--enabled-tools Tools whitelist (only the specified tools will be enabled)
|
--enabled-tools Tools whitelist (only the specified tools will be enabled)
|
||||||
--disabled-tools Tools blacklist (included tools will be disabled)
|
--disabled-tools Tools blacklist (included tools will be disabled)
|
||||||
|
--stateless <boolean> HTTP Stateless flag
|
||||||
```
|
```
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ services:
|
|||||||
- BRAVE_API_KEY
|
- BRAVE_API_KEY
|
||||||
- BRAVE_MCP_TRANSPORT=http
|
- BRAVE_MCP_TRANSPORT=http
|
||||||
- BRAVE_MCP_PORT=8080
|
- BRAVE_MCP_PORT=8080
|
||||||
|
- BRAVE_MCP_STATELESS
|
||||||
- BRAVE_MCP_HOST=0.0.0.0
|
- BRAVE_MCP_HOST=0.0.0.0
|
||||||
- BRAVE_MCP_LOG_LEVEL=info
|
- BRAVE_MCP_LOG_LEVEL=info
|
||||||
- BRAVE_MCP_ENABLED_TOOLS
|
- BRAVE_MCP_ENABLED_TOOLS
|
||||||
|
|||||||
@@ -43,9 +43,9 @@
|
|||||||
"Description": "MCP protocol transport mode. Supported values are \"http\" or \"stdio\", however Bedrock Agentcore only supports \"http\" (reference https://docs.aws.amazon.com/marketplace/latest/userguide/bedrock-agentcore-runtime.html#agentcore-container-requirements)."
|
"Description": "MCP protocol transport mode. Supported values are \"http\" or \"stdio\", however Bedrock Agentcore only supports \"http\" (reference https://docs.aws.amazon.com/marketplace/latest/userguide/bedrock-agentcore-runtime.html#agentcore-container-requirements)."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"DefaultValue": "8080",
|
"DefaultValue": "8000",
|
||||||
"Name": "BRAVE_MCP_PORT",
|
"Name": "BRAVE_MCP_PORT",
|
||||||
"Description": "HTTP server port (default: 8080). Mandatory port for Bedrock Agentcore is 8080 (reference https://docs.aws.amazon.com/marketplace/latest/userguide/bedrock-agentcore-runtime.html#agentcore-container-requirements)."
|
"Description": "HTTP server port (default: 8000). Mandatory port for Bedrock Agentcore is 8000 (reference https://docs.aws.amazon.com/marketplace/latest/userguide/bedrock-agentcore-runtime.html#agentcore-container-requirements)."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"DefaultValue": "0.0.0.0",
|
"DefaultValue": "0.0.0.0",
|
||||||
@@ -64,6 +64,11 @@
|
|||||||
{
|
{
|
||||||
"Name": "BRAVE_MCP_DISABLED_TOOLS",
|
"Name": "BRAVE_MCP_DISABLED_TOOLS",
|
||||||
"Description": "*Optional* When used, specifies a blacklist for supported tools"
|
"Description": "*Optional* When used, specifies a blacklist for supported tools"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DefaultValue": "true",
|
||||||
|
"Name": "BRAVE_MCP_STATELESS",
|
||||||
|
"Description": "Sets HTTP Stateless mode (default: true). When deploying on Bedrock Agentcore, this should be set to true."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-3
@@ -34,6 +34,11 @@ export const configSchema = z.object({
|
|||||||
.default('info')
|
.default('info')
|
||||||
.describe('Desired logging level')
|
.describe('Desired logging level')
|
||||||
.optional(),
|
.optional(),
|
||||||
|
stateless: z
|
||||||
|
.boolean()
|
||||||
|
.default(false)
|
||||||
|
.describe('Whether the server should be stateless')
|
||||||
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type SmitheryConfig = z.infer<typeof configSchema>;
|
export type SmitheryConfig = z.infer<typeof configSchema>;
|
||||||
@@ -46,6 +51,7 @@ type Configuration = {
|
|||||||
loggingLevel: LoggingLevel;
|
loggingLevel: LoggingLevel;
|
||||||
enabledTools: string[];
|
enabledTools: string[];
|
||||||
disabledTools: string[];
|
disabledTools: string[];
|
||||||
|
stateless: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const state: Configuration & { ready: boolean } = {
|
const state: Configuration & { ready: boolean } = {
|
||||||
@@ -57,6 +63,7 @@ const state: Configuration & { ready: boolean } = {
|
|||||||
ready: false,
|
ready: false,
|
||||||
enabledTools: [],
|
enabledTools: [],
|
||||||
disabledTools: [],
|
disabledTools: [],
|
||||||
|
stateless: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function isToolPermittedByUser(toolName: string): boolean {
|
export function isToolPermittedByUser(toolName: string): boolean {
|
||||||
@@ -77,12 +84,12 @@ export function getOptions(): Configuration | false {
|
|||||||
.option(
|
.option(
|
||||||
'--enabled-tools <names...>',
|
'--enabled-tools <names...>',
|
||||||
'tools to enable',
|
'tools to enable',
|
||||||
process.env.BRAVE_MCP_ENABLED_TOOLS?.split(' ') ?? []
|
process.env.BRAVE_MCP_ENABLED_TOOLS?.trim().split(' ') ?? []
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'--disabled-tools <names...>',
|
'--disabled-tools <names...>',
|
||||||
'tools to disable',
|
'tools to disable',
|
||||||
process.env.BRAVE_MCP_DISABLED_TOOLS?.split(' ') ?? []
|
process.env.BRAVE_MCP_DISABLED_TOOLS?.trim().split(' ') ?? []
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
'--port <number>',
|
'--port <number>',
|
||||||
@@ -94,6 +101,11 @@ export function getOptions(): Configuration | false {
|
|||||||
'desired host for HTTP transport',
|
'desired host for HTTP transport',
|
||||||
process.env.BRAVE_MCP_HOST ?? '0.0.0.0'
|
process.env.BRAVE_MCP_HOST ?? '0.0.0.0'
|
||||||
)
|
)
|
||||||
|
.option(
|
||||||
|
'--stateless <boolean>',
|
||||||
|
'whether the server should be stateless',
|
||||||
|
process.env.BRAVE_MCP_STATELESS === 'true' ? true : false
|
||||||
|
)
|
||||||
.allowUnknownOption()
|
.allowUnknownOption()
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
@@ -108,7 +120,11 @@ export function getOptions(): Configuration | false {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([...enabledTools, ...disabledTools].some((t) => !toolNames.includes(t))) {
|
if (
|
||||||
|
[...enabledTools, ...disabledTools].some(
|
||||||
|
(t) => t.trim().length > 0 && !toolNames.includes(t.trim())
|
||||||
|
)
|
||||||
|
) {
|
||||||
console.error(`Invalid tool name used. Must be one of: ${toolNames.join(', ')}`);
|
console.error(`Invalid tool name used. Must be one of: ${toolNames.join(', ')}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -149,6 +165,9 @@ export function getOptions(): Configuration | false {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalize stateless to boolean (CLI passes it as string)
|
||||||
|
options.stateless = options.stateless === true || options.stateless === 'true';
|
||||||
|
|
||||||
// Update state
|
// Update state
|
||||||
state.braveApiKey = options.braveApiKey;
|
state.braveApiKey = options.braveApiKey;
|
||||||
state.transport = options.transport;
|
state.transport = options.transport;
|
||||||
@@ -157,6 +176,7 @@ export function getOptions(): Configuration | false {
|
|||||||
state.loggingLevel = options.loggingLevel;
|
state.loggingLevel = options.loggingLevel;
|
||||||
state.enabledTools = options.enabledTools;
|
state.enabledTools = options.enabledTools;
|
||||||
state.disabledTools = options.disabledTools;
|
state.disabledTools = options.disabledTools;
|
||||||
|
state.stateless = options.stateless;
|
||||||
state.ready = true;
|
state.ready = true;
|
||||||
|
|
||||||
return options as Configuration;
|
return options as Configuration;
|
||||||
|
|||||||
+10
-1
@@ -37,13 +37,22 @@ const getTransport = async (request: Request): Promise<StreamableHTTPServerTrans
|
|||||||
return transport;
|
return transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let transport: StreamableHTTPServerTransport;
|
||||||
|
|
||||||
|
if (config.stateless) {
|
||||||
|
// Some contexts (e.g. AgentCore) may prefer or require a stateless transport
|
||||||
|
transport = new StreamableHTTPServerTransport({
|
||||||
|
sessionIdGenerator: undefined,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
// Otherwise, start a new transport/session
|
// Otherwise, start a new transport/session
|
||||||
const transport = new StreamableHTTPServerTransport({
|
transport = new StreamableHTTPServerTransport({
|
||||||
sessionIdGenerator: () => randomUUID(),
|
sessionIdGenerator: () => randomUUID(),
|
||||||
onsessioninitialized: (sessionId) => {
|
onsessioninitialized: (sessionId) => {
|
||||||
transports.set(sessionId, transport);
|
transports.set(sessionId, transport);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const mcpServer = createMcpServer();
|
const mcpServer = createMcpServer();
|
||||||
await mcpServer.connect(transport);
|
await mcpServer.connect(transport);
|
||||||
|
|||||||
Reference in new issue
Block a user