Skip to content

MCPServer#invalidateToolsCache() not exposed while being mentioned in the documents #219

@matheusgalvao1

Description

@matheusgalvao1

Describe the bug

invalidateToolsCache() is advertised in the docs and present in the Node/Browser shim classes, but it is not exposed by the public wrapper classes MCPServerStdio and MCPServerStreamableHttp. Calling the method on an instance created from @openai/agents therefore throws:

TypeError: mcpServer.invalidateToolsCache is not a function

The only workaround is to use the global invalidateServerToolsCache(name) helper and recreate the server object, or disable caching entirely.

Debug information

Repro steps

Run the following minimal script:

import { MCPServerStreamableHttp } from "@openai/agents";

const mcpServer = new MCPServerStreamableHttp({
  url: "http://localhost:3000/mcp",
  name: "Local MCP",
  cacheToolsList: true,
});

await mcpServer.connect();
await mcpServer.invalidateToolsCache(); // ← throws TypeError

Expected output: no error, cache cleared.
Actual output: TypeError: mcpServer.invalidateToolsCache is not a function.

Expected behavior

invalidateToolsCache() should be callable on any MCPServerStdio/MCPServerStreamableHttp instance and clear the per‑instance tools cache so the next run performs a fresh tools/list request—mirroring the behaviour of the global invalidateServerToolsCache(name) helper.

Additional context

Layer File Method present?
Node shim packages/agents-core/src/shims/mcp-server/node.ts yes
Browser shim packages/agents-core/src/shims/mcp-server/browser.ts yes
Public wrapper packages/agents-core/src/mcp.ts missing

Docs/examples assume the instance method exists; Python SDK still exposes invalidate_tools_cache() at the instance level, so parity is expected.

Proposed fix

Add a passthrough method in the public wrappers:

invalidateToolsCache(): void {
  this.underlying.invalidateToolsCache();
  this._cachedTools = undefined; // optional: clear local copy
}

Happy to submit a PR if helpful, thanks for maintaining the SDK!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions