Skip to content

Breaking: reject invalid Strands TypeScript MCP factory results - #535

Merged
campoy merged 2 commits into
mainfrom
fix/strands-ts-mcp-factory-types
Nov 16, 2026
Merged

campoy merged 2 commits into
mainfrom
fix/strands-ts-mcp-factory-types

Conversation

@campoy

@campoy campoy commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

An MCP factory that returns undefined, null or an incomplete client currently fails with a retryable runtime error. Check for callable connect, disconnect, listTools and callTool methods before connecting the client.

An invalid result fails with a non-retryable MCPClientFactoryTypeError that names the factory and what it returned:

MCP client factory 'weather' returned Client, not a client with connect(), disconnect(), listTools() and callTool() methods.

The check covers both MCP Activities through their shared connection pool. Structural clients and test doubles still work. Factory exceptions keep their existing handling.

A factory that isn't a function, such as a client passed in its place, fails with a TypeError when the StrandsPlugin is built:

MCP client factory 'weather' is McpClient, not a function.

This changes only factory validation. No new dependency or MCP package release is needed.

Is it breaking? (Breaking)

Invalid clients now stop the Activity without retries, including on the next attempt of an in-flight Activity. A partial client that previously worked for one operation must provide all four methods. Fix these factories before upgrading Workers. Deploying a corrected Worker will not automatically resume an Activity that has already failed. No Workflow code or Activity names change.

A factory that isn't a function now stops the Worker from starting, even when no Workflow uses that server.

Checklist

  1. Related: [strands-agents-python] breaking: refuse misconfigured MCP factories and correct the MCP README #377, Breaking: reject invalid Vercel AI SDK MCP client factory results #529 and Breaking: reject invalid MCP factories in OpenAI Agents TypeScript #530. No issue to close.
  2. Validation:
    • The two new wrong-result cases fail on the original code with a TypeError from connect and pass with the check.
    • The invalid-result test checks the message for each returned value, including an MCP SDK Client. It also passes each invalid value in place of the factory and checks the TypeError.
    • Removing the factory check, or the description of the returned value, fails both invalid-result tests.
    • make test TEST_ARGS='lib/__tests__/test-mcp-connection-eviction.js': 8 passed. Checks invalid results, no method calls before rejection, factory exceptions and existing connection behavior.
    • make test TEST_ARGS='lib/__tests__/test-strands-mcp-connections.js lib/__tests__/test-strands-mcp-tools.js': 11 passed.
    • make test TEST_ARGS='lib/__tests__/test-strands-plugin.js': 3 passed.
    • make lint, make build and git diff --check passed.
    • Local checks used Node 22.23.4 and the repository's pinned pnpm 10.27.0. The lockfile and package-manager settings are unchanged.
  3. Docs: the README includes the required methods and upgrade warning.

@campoy
campoy marked this pull request as ready for review November 14, 2026 01:33
@campoy
campoy requested a review from a team as a code owner November 14, 2026 01:33
The error now says what the factory returned, such as `undefined` or the
MCP SDK's `Client`. A factory that isn't a function fails when the
StrandsPlugin is built instead of in every MCP Activity.

The invalid-result test now includes an MCP SDK `Client` and passes each
invalid value in place of the factory.
campoy added a commit that referenced this pull request Nov 14, 2026
## What was changed

When a Vercel AI SDK MCP client factory resolves to `undefined`, `null`,
or an object without the required methods, the Activity fails with an
opaque `TypeError`. The default retry policy repeats that failure
without limit, and cleanup can hide the original error with another
`TypeError` about `close`.

Validate each factory result before using it. A client must expose
callable `tools()` and `close()` methods, the two methods this adapter
uses. An invalid result fails with a non-retryable
`MCPClientFactoryTypeError` that names the factory and what it returned:

```
MCP client factory 'weather' returned Client, not a client with tools() and close() methods.
```

If a rejected result still has a callable `close()`, such as a connected
MCP SDK `Client`, it is closed first so the connection doesn't leak. An
error from that `close()` doesn't replace the validation failure.

A factory that isn't a function, such as a connected client passed in
its place, fails with a `TypeError` when the Worker is built:

```
MCP client factory 'weather' is DefaultMCPClient, not a function.
```

The check covers list-tools and call-tool Activities, with connection
pooling enabled or disabled. Factories that throw or reject pass their
errors through to the Activity retry policy. Objects that implement the
required methods, including test doubles, remain supported.

## Why?

Wrong factory results are configuration errors. Failing them without
retries is the behavior we agreed for the MCP factory checks in the
other plugins: OpenAI Agents TypeScript (#530), OpenAI Agents Python
(#451), Strands Python (#377), Strands TypeScript (#535), Google GenAI
(#531) and Google ADK (#534, #536). This change is contained in the
Vercel AI SDK plugin and needs no `temporalio-mcp` release.

## Is it breaking? (Breaking)

Invalid clients now stop the Activity without retries. A client missing
`close()` could previously serve pooled requests until eviction; it is
now rejected before use. The check also runs on the next attempt of an
in-flight Activity. Fix these factories before upgrading: deploying a
corrected Worker will not automatically resume an Activity that has
already failed.

A factory that isn't a function now stops the Worker from starting, even
when no Workflow uses that server.

No Workflow code or Activity names change. The README includes the
factory requirements and upgrade warning.

## Checklist

1. Closes: no issue. Related to #451, #377 and #530.

2. How was this tested:
- The invalid-client cases fail on the original code with `TypeError`s
from `tools` or `close`, and pass with the change. They check the
message for each returned value, and that rejected clients with a
callable `close()` are closed, including when `close()` throws or
rejects. They also pass each invalid value in place of the factory and
check the `TypeError`.
- The same test returns a connected MCP SDK `Client` from the factory
and checks that its in-memory server sees the connection close, in all
four operation and pooling combinations.
- Removing each fix in turn (the factory check, closing rejected
clients, closing only the MCP SDK `Client`) fails all four
invalid-client tests.
- `make test TEST_ARGS='lib/__tests__/test-ai-sdk-mcp-connections.js'`:
14 passed. Covers invalid clients, unchanged factory failures, and
existing connection reuse and cleanup behavior.
- `make test TEST_ARGS='lib/__tests__/test-ai-sdk-mcp-tools.js
lib/__tests__/test-ai-sdk-plugin.js'`: 5 passed, 1 existing test
skipped. The MCP Workflow test uses a real AI SDK MCP client.
   - `make lint`, `make build` and `git diff --check` passed.
- Local checks used Node 22.23.4 and the repository's pinned pnpm
10.27.0. The lockfile and package-manager settings are unchanged.

3. Any docs updates needed? The plugin README is updated.
@campoy
campoy merged commit 7d5d8d1 into main Nov 16, 2026
27 checks passed
@campoy
campoy deleted the fix/strands-ts-mcp-factory-types branch November 16, 2026 06:11
campoy added a commit that referenced this pull request Nov 16, 2026
…sn't a server (#589)

## What was changed

When an OpenAI Agents TypeScript MCP factory returns something that
isn't a server, the Activity error now says what came back:

```
MCP server factory 'files' returned Promise, not a server with connect(), close(), listTools() and callTool() methods.
```

Before, it said `returned an invalid server` for every value. The name
helps: `undefined` points at a missing `return`, and `Promise` at an
`async` factory. The error type (`MCPServerFactoryTypeError`) and the
non-retryable flag don't change.

## Why?

The review on #529 asked for errors that name the bad value. The Vercel
AI SDK (#529), Strands (#535) and Google ADK (#534, #536) plugins do
that now. #530 merged before that review, so OpenAI Agents TypeScript is
the one left.

This PR is stacked on #555, which adds the `describeValue` helper it
uses. Merge #555 first. GitHub then moves this PR to `main`, and I'll
rebase it so the diff shows only this change.

## Checklist

1. Closes: no issue. Follow-up to #530.

2. How was this tested:
- The existing test in `mcp-provider.test.ts` now checks the full
message for each invalid result: `undefined`, `null`, a number, a plain
object, a `Promise` and an incomplete server. It fails with the old
message and passes with the new one.
- On macOS with Node 22: the TypeScript build and the `mcp-provider`
test file (6 passed).
- In a Linux container with Node 24: ESLint (0 errors; the 8 warnings
are the existing `ActivityOptions` ones). I left the full `make test` to
CI.

3. Any docs updates needed? No. The README doesn't quote the message.
campoy added a commit that referenced this pull request Nov 16, 2026
… a function (#555)

## What was changed

`StatelessMCPServerProvider` and `StatefulMCPServerProvider` now check
that their factory is a function when you create them. If it isn't, they
throw a `TypeError` that says what was passed, such as `MCP server
factory 'files' is Object, not a function.`, so the Worker doesn't
start. The message matches the Vercel AI SDK, Strands and Google ADK
plugins.

## Why?

Today a factory that isn't a function, say a server instead of a
function that returns one, gets past Worker start. Then every MCP
Activity for that server fails with a plain `TypeError` that retries
forever. #530 only checks what the factory returns.

#529 added this check to the Vercel AI SDK plugin, and #531, #534, #535
and #536 add it to the other plugins. This does the same here, before
2.0, since adding it later would stop Workers that start today.

## Is it breaking? (Breaking)

A Worker with a factory that isn't a function used to start, even though
each MCP Activity for that server failed. Now it doesn't start, even
when no Workflow uses that server. Fix the factory before upgrading. No
Workflow code or Activity names change.

## Checklist

1. Related: #529 and #530. No issue to close.

2. How was this tested:
- A new test in `mcp-provider.test.ts` checks that both providers throw
the `TypeError` for `undefined`, `null`, a number and a server object,
and that the message names each one. With the check turned off, it
fails.
- On macOS with Node 22: the TypeScript build and the `mcp-provider`
test file (6 passed).
- In a Linux container with Node 24: ESLint (0 errors; the 8 warnings
are the existing `ActivityOptions` ones). I left the full `make test` to
CI.
   - `git diff --check` passes.

3. Any docs updates needed? The README's factory section now says it.
campoy added a commit that referenced this pull request Nov 16, 2026
…lable (#593)

## What was changed

`OpenAIAgentsPlugin(mcp_servers=...)` now checks that each factory is
callable when the plugin is built. If it isn't, it raises `TypeError`,
so the Worker doesn't start:

```
MCP server factory 'filesystem' is agents.mcp.server.MCPServerStreamableHttp, not callable
```

Today a server passed in place of its factory gets past Worker start.
Then every MCP Activity for that server fails with `TypeError:
'MCPServerStreamableHttp' object is not callable`, which the default
retry policy retries forever.

There's a second, smaller fix. When an async factory returns a
coroutine, the Activity already fails with `MCPServerFactoryTypeError`
(#451), but Python also warns that the coroutine was never awaited. The
coroutine is now closed first.

Both checks live in this plugin's `_mcp_server_backend_factory`, like
`MCPPlugin`'s in #539, not in the `_FactoryInvoker` this plugin imports
from `temporalio-mcp`.

## Why?

The other MCP plugins refuse a factory that isn't a function when the
Worker is built: #529, #531, #534, #535, #536 and #555, plus
`temporalio-mcp` and Strands Python with #539 and #377. #531 also closes
a returned coroutine, after its review asked for it. This brings OpenAI
Agents Python in line.

## Is it breaking? (Breaking)

A Worker with a factory that isn't callable used to start, even though
every MCP Activity for that server failed and retried. Now it doesn't
start, even when no workflow uses that server. Fix the factory before
upgrading. No Workflow code or Activity names change.

The deprecated `mcp_server_providers` route doesn't change. Its
providers don't check what the factory returns at all, and I left them
alone because they're deprecated.

## Checklist

1. Closes: no issue. Follow-up to #451.

2. How was this tested:
- The existing test in `test_mcp_v2.py` now also runs with an async
factory, and first passes the returned value in place of the factory.
Without the startup check it fails with `DID NOT RAISE TypeError`, and
without the `close()` with `CORO_CREATED`. It passes with both.
   - `make test` on Python 3.12: 644 passed, 2 skipped.
   - `make lint` passed.
   - `git diff --check` passed.

3. Any docs updates needed? The README's MCP section now describes both
factory errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants