Repository navigation
Description
What happens
StatelessMCPServerProvider and StatefulMCPServerProvider (@temporalio/openai-agents) take a factory that returns a native MCP server, such as MCPServerStdio or MCPServerStreamableHttp. The OpenAI Agents SDK's MCP guide lists toolFilter as an option of those servers: "You can restrict which tools are exposed from each server by passing either a static filter via createMCPToolStaticFilter or a custom function."
Through the plugin, that filter is ignored. The model is offered the blocked tools and can call them, and they run. Nothing fails or warns.
Cause: a native server's listTools() returns every tool, and the agent filters afterwards, reading toolFilter from the server object it holds. In a Workflow that object is the handle from statelessMcpServer() or statefulMcpServer(). The handle has no toolFilter, and its options take none. The factory's server, with the filter, exists only inside the list-tools and call-tool Activities, which never read it.
Reproduction
One file. It needs a dev server (temporal server start-dev) and writes its Workflow file next to itself. The factory's server blocks danger_tool; a fake model calls danger_tool only if it is offered. The script exits 0 when the plugin route offers and runs the blocked tool.
// issue_repro.js: a toolFilter on the MCP server that a StatelessMCPServerProvider factory returns is ignored.
// Needs a Temporal dev server (`temporal server start-dev`). Usage: node issue_repro.js [address]
// The script writes its Workflow file next to itself. Exits 0 when the blocked tool is offered and runs.
const fs = require('node:fs');
const path = require('node:path');
const { Agent, Runner, Usage, createMCPToolStaticFilter } = require('@openai/agents-core');
const { Client, Connection } = require('@temporalio/client');
const { NativeConnection, Runtime, DefaultLogger, Worker } = require('@temporalio/worker');
const { OpenAIAgentsPlugin, StatelessMCPServerProvider } = require('@temporalio/openai-agents');
const workflowsPath = path.join(__dirname, 'issue_repro_workflows.js');
fs.writeFileSync(
workflowsPath,
`const { Agent } = require('@openai/agents-core');
const { TemporalOpenAIRunner, statelessMcpServer } = require('@temporalio/openai-agents/workflow');
exports.mcpAgent = async () => {
const agent = new Agent({ name: 'ops', instructions: 'Use the tools.', model: 'fake', mcpServers: [statelessMcpServer('ops')] });
return (await new TemporalOpenAIRunner().run(agent, 'go')).finalOutput;
};
`
);
// The factory's server blocks danger_tool, as in the framework's MCP guide.
const ran = [];
const schema = { type: 'object', properties: {}, required: [], additionalProperties: false };
const factory = () => ({
name: 'ops',
cacheToolsList: false,
toolFilter: createMCPToolStaticFilter({ blocked: ['danger_tool'] }),
async connect() {},
async close() {},
async invalidateToolsCache() {},
async listTools() {
return [
{ name: 'safe_tool', description: 'Safe.', inputSchema: schema },
{ name: 'danger_tool', description: 'Blocked.', inputSchema: schema },
];
},
async callTool(name) {
ran.push(name);
return [{ type: 'text', text: `${name} ran` }];
},
});
// A fake model: calls danger_tool if it is offered, then answers.
const offered = [];
const message = (text) => ({
usage: new Usage(),
output: [{ type: 'message', id: 'm', role: 'assistant', status: 'completed', content: [{ type: 'output_text', text }] }],
});
const model = {
async getResponse(request) {
if (request.input.some?.((item) => item.type === 'function_call_result')) return message('done');
const names = request.tools.map((tool) => tool.name);
offered.push(names);
if (!names.includes('danger_tool')) return message('danger_tool not offered');
return {
usage: new Usage(),
output: [{ type: 'function_call', id: 'fc', callId: 'call', name: 'danger_tool', arguments: '{}', status: 'completed' }],
};
},
async *getStreamedResponse() {
throw new Error('not used');
},
};
async function main() {
const address = process.argv[2] ?? '127.0.0.1:7233';
Runtime.install({ logger: new DefaultLogger('ERROR') });
// Native control: the same server and model with the framework's Runner.
const agent = new Agent({ name: 'ops', instructions: 'Use the tools.', model: 'fake', mcpServers: [factory()] });
await new Runner({ modelProvider: { getModel: () => model }, tracingDisabled: true }).run(agent, 'go');
console.log(`native: offered ${JSON.stringify(offered[0])}, ran ${JSON.stringify(ran)}`);
ran.length = 0;
// Plugin: the same factory on a StatelessMCPServerProvider.
const plugin = new OpenAIAgentsPlugin({
modelProvider: { getModel: () => model },
mcpServerProviders: [new StatelessMCPServerProvider('ops', factory)],
});
const taskQueue = `mcp-filter-${Date.now()}`;
const worker = await Worker.create({
connection: await NativeConnection.connect({ address }),
taskQueue,
workflowsPath,
plugins: [plugin],
});
const client = new Client({ connection: await Connection.connect({ address }), plugins: [plugin] });
await worker.runUntil(client.workflow.execute('mcpAgent', { taskQueue, workflowId: taskQueue }));
console.log(`plugin: offered ${JSON.stringify(offered[1])}, ran ${JSON.stringify(ran)}`);
return offered[1].includes('danger_tool') && ran.includes('danger_tool');
}
main().then(
(bug) => process.exit(bug ? 0 : 1),
(err) => {
console.error(err);
process.exit(2);
}
);With @temporalio/openai-agents 1.24.0 (npm, the latest release) and with the package built from this repository's main (c664a34), both with @temporalio/* 1.24.0, @openai/agents-core 0.14.3, Node v24.22.0 and Temporal CLI 1.9.1:
$ node issue_repro.js
native: offered ["safe_tool"], ran []
plugin: offered ["safe_tool","danger_tool"], ran ["danger_tool"]
exit=0
The same happens with a real stdio server: MCPServerStdio with createMCPToolStaticFilter({ allowed: ['safe_tool'], blocked: ['danger_tool'] }) and an @modelcontextprotocol/sdk 1.32.1 server. The History holds ops-stateless-list-tools, invokeModelActivity, ops-stateless-call-tool, invokeModelActivity, and the blocked tool's handler ran once. A stateful server behaves the same way.
Control: a filter assigned to the handle in Workflow code (server.toolFilter = ...) works. That property is part of the framework's MCPServer interface, but the plugin doesn't document it.
Expected
The model is offered the same tools as with the native server: the blocked tool is not offered.
Impact
A tool that the configuration says the agent must not see is offered and runs, with no error or warning. Only servers with a toolFilter are affected. The framework guide documents the option, and two of the six local-server examples in its examples/mcp/ use it.
Proposed fix
- In the list-tools Activities, apply the factory server's static filter (
allowedToolNamesandblockedToolNames) with the same rules the agent uses. - A callable filter gets the
Agentand the run context, which exist only in the Workflow and can't be sent to an Activity in full. Add atoolFilteroption tostatelessMcpServer()andstatefulMcpServer()that the agent applies in the Workflow, as it does natively. It must be deterministic. The Worker keeps skipping a callable filter on the factory's server, now with a warning.
Code with a static filter is fixed without changes; code with a callable filter must move it to the new option. Open runs replay the same: list-tools results are recorded in History.
useStructuredContent, errorFunction and customDataExtractor on the factory's server are ignored the same way; they are not covered here.
A PR follows.
Activity