Skip to content

MCPs loading are now non-blocking and can take time to load.#2050

Merged
robgruen merged 18 commits intomainfrom
dev/robgruen/mcp_non_blocking_loading
Mar 24, 2026
Merged

MCPs loading are now non-blocking and can take time to load.#2050
robgruen merged 18 commits intomainfrom
dev/robgruen/mcp_non_blocking_loading

Conversation

@robgruen
Copy link
Collaborator

Key changes include:

Support for HTTP-based (server-command) agents

  • Added support for HTTP-based agents via StreamableHTTPClientTransport, including logic to launch and manage background server processes, check for occupied ports, and connect to running servers. This enables agents that are started via command-line and communicate over HTTP, not just stdio. (mcpAgentProvider.ts) [1] [2] [3] [4] [5]

  • Implemented background agent startup and management, ensuring that server processes are started only when necessary and tracked to prevent duplicate launches or premature shutdowns. (mcpAgentProvider.ts)

Asynchronous schema loading and manifest readiness

  • Introduced the onSchemaReady callback and getLoadingAgentNames API in AppAgentProvider, allowing the UI and other consumers to be notified when an agent's schema is available and to track which agents are still loading. (agentProvider.ts, mcpAgentProvider.ts) [1] [2]

  • Modified getAppAgentManifest to return a stub manifest for slow-loading agents and to trigger background loading, improving responsiveness and user feedback in the UI. (mcpAgentProvider.ts)

Enhanced error handling and process cleanup

  • Improved error handling for agent startup and connection failures, ensuring that resources (transports, server processes) are properly cleaned up and errors are logged for debugging. (mcpAgentProvider.ts) [1] [2]

Dispatcher and agent manager integration

  • Updated the dispatcher and AppAgentManager to track loading schemas, expose schema loading status, and support new provider APIs for asynchronous agent readiness. (appAgentManager.ts) [1] [2] [3]

These changes collectively enable a more robust and flexible agent provider system, especially for agents that require asynchronous or background initialization.
This pull request significantly enhances the flexibility and robustness of the MCP (Model Context Protocol) agent provider system by introducing support for HTTP-based agents that start asynchronously, improving process management, and enabling better UI feedback for agents that are still loading. The changes also add new APIs for tracking agent loading status and notifying consumers when agent schemas are ready, which is especially important for agents that require time to start up.

The `agent-dispatcher` package failed to build due to several TypeScript
type errors introduced by recent API changes that weren't propagated to
all call sites.

### `CompletionGroups` return type mismatch (`configCommandHandlers.ts`)
`CommandHandler.getCompletion` was updated to return
`Promise<CompletionGroups>` (wrapped object with `groups` property), but
7 implementations still returned `Promise<CompletionGroup[]>`:
```ts
// Before
return completions; // CompletionGroup[]

// After
return { groups: completions }; // CompletionGroups
```

### Missing properties on `CommandHandlerContext`
(`commandHandlerContext.ts`)
Three properties used in `command.ts` and `dispatcher.ts` were missing
from the type definition:
- `currentAbortSignal: AbortSignal | undefined`
- `activeRequests: Map<string, AbortController>`
- `displayLog: DisplayLog`

Added to the type and initialized in the context factory (`undefined`,
`new Map()`, and `await DisplayLog.load(persistDir)` respectively).

### Wrong callback return type in `configureGrammarGeneration`
(`commandHandlerContext.ts`)
The callback passed to `configureGrammarGeneration` returned a `string`
(file path) but the signature requires `(schemaName: string) =>
ParsedActionSchema`. Also referenced the non-existent
`actionConfig.compiledSchemaFilePath` field. Fixed to load and parse the
`.pas.json` file:
```ts
const content = fs.readFileSync(schemaPath, "utf-8");
return fromJSONParsedActionSchema(JSON.parse(content) as ParsedActionSchemaJSON);
```

### Non-existent `compiledSchemaFilePath` on `ActionConfig`
(`appAgentManager.ts`)
Same dead field access; replaced with
`config.schemaFilePath?.endsWith(".pas.json")` check.

<!-- START COPILOT CODING AGENT SUFFIX -->



<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> Fix the failing GitHub Actions workflow build_ts (windows-latest, 20)
> Analyze the workflow logs, identify the root cause of the failure, and
implement a fix.
> Job ID: 68255852060
> Job URL:
https://github.com/microsoft/TypeAgent/actions/runs/23459055003/job/68255852060


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

📍 Connect Copilot coding agent with [Jira](https://gh.io/cca-jira-docs),
[Azure Boards](https://gh.io/cca-azure-boards-docs) or
[Linear](https://gh.io/cca-linear-docs) to delegate work to Copilot in
one click without leaving your project management tool.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: robgruen <25374553+robgruen@users.noreply.github.com>
…ma and wrong enrichGrammarWithCheckedVariables argument (#2054)

The `agent-dispatcher` package failed to build on Windows due to two
type errors introduced by API changes that weren't propagated to all
call sites.

## Changes

- **`enrichGrammarWithCheckedVariables` call site**
(`appAgentManager.ts`): The function signature changed from accepting a
`.pas.json` file path `string` to a `ParsedActionSchema` object. Updated
the call to pass `actionSchemaFile.parsedActionSchema` (already in
scope), eliminating a redundant file read and the now-unused
`getPackageFilePath` import.

  ```ts
  // Before — passed file path string, wrong type
  const pasJsonPath = getPackageFilePath(compiledSchemaFilePath);
  enrichGrammarWithCheckedVariables(g, pasJsonPath);

  // After — uses already-loaded parsed schema
enrichGrammarWithCheckedVariables(g,
actionSchemaFile.parsedActionSchema);
  ```

- **`reloadAgentSchema` missing from `AppAgentManager`**
(`sessionContext.ts`, `claude.ts`): Both call sites invoked
`context.agents.reloadAgentSchema(name, context)` but the method didn't
exist. Added the implementation, which:
1. Unloads cached schema files for all schemas belonging to the agent
(forces re-read from disk)
2. Fetches a fresh manifest from the provider and calls
`refreshAgentSchema`
3. Clears the translator cache so subsequent requests use the updated
schema

<!-- START COPILOT CODING AGENT SUFFIX -->



<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> Fix the failing GitHub Actions workflow build_package_shell
(windows-latest, 22)
> Analyze the workflow logs, identify the root cause of the failure, and
implement a fix.
> Job ID: 68259596486
> Job URL:
https://github.com/microsoft/TypeAgent/actions/runs/23460182903/job/68259596486


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

📱 Kick off Copilot coding agent tasks wherever you are with [GitHub
Mobile](https://gh.io/cca-mobile-docs), available on iOS and Android.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: robgruen <25374553+robgruen@users.noreply.github.com>
…ms` (#2055)

The `build_package_shell` CI job was failing because
`getMcpCommandHandlerTable` in `mcpAgentProvider.ts` accessed
`params.tokens`, which only exists on the internal
`ParseParamsResult<T>` type (dispatcher package), not on the public
`ParsedCommandParams<T>` from `@typeagent/agent-sdk`.

## Changes

- **`mcpAgentProvider.ts`**: Replace `params.tokens` with an explicit
collection of arg values from `params.args`, keyed by the
`ArgDefinitions` passed to the outer function (preserving definition
order):
  ```typescript
  const serverScriptArgs = Object.keys(args).map((k) =>
      String((params.args as Record<string, unknown>)[k]),
  );
  ```
- Update the `run` callback parameter type from
`ParsedCommandParams<{}>` to `ParsedCommandParams<ParameterDefinitions>`
to match the `CommandHandler` interface.
- Add `ParameterDefinitions` to the import from `@typeagent/agent-sdk`.

<!-- START COPILOT CODING AGENT SUFFIX -->



<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> Fix the failing GitHub Actions workflow build_package_shell
(windows-latest, 22)
> Analyze the workflow logs, identify the root cause of the failure, and
implement a fix.
> Job ID: 68268369843
> Job URL:
https://github.com/microsoft/TypeAgent/actions/runs/23462848733/job/68268369843


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

⌨️ Start Copilot coding agent tasks without leaving your editor —
available in [VS Code](https://gh.io/cca-vs-code-docs), [Visual
Studio](https://gh.io/cca-visual-studio-docs), [JetBrains
IDEs](https://gh.io/cca-jetbrains-docs) and
[Eclipse](https://gh.io/cca-eclipse-docs).

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: robgruen <25374553+robgruen@users.noreply.github.com>
The `build_ts` CI workflow was failing due to a prettier check violation
in `agent-dispatcher`'s `appAgentManager.ts`. Two recently added lines
exceeded the max line length.

## Changes
-
**`ts/packages/dispatcher/dispatcher/src/context/appAgentManager.ts`**:
Reformatted two overly long expressions to comply with prettier
line-length rules:
- Wrapped `await record.provider.getAppAgentManifest(appAgentName)`
assignment
- Expanded `this.refreshAgentSchema(appAgentName, manifest,
semanticMapP, undefined)` to multi-line call

```ts
// Before
const manifest = await record.provider.getAppAgentManifest(appAgentName);
this.refreshAgentSchema(appAgentName, manifest, semanticMapP, undefined);

// After
const manifest =
    await record.provider.getAppAgentManifest(appAgentName);
this.refreshAgentSchema(
    appAgentName,
    manifest,
    semanticMapP,
    undefined,
);
```

<!-- START COPILOT CODING AGENT SUFFIX -->



<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> Fix the failing GitHub Actions workflow build_ts (ubuntu-latest, 22)
> Analyze the workflow logs, identify the root cause of the failure, and
implement a fix.
> Job ID: 68269878964
> Job URL:
https://github.com/microsoft/TypeAgent/actions/runs/23463307901/job/68269878964


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

📍 Connect Copilot coding agent with [Jira](https://gh.io/cca-jira-docs),
[Azure Boards](https://gh.io/cca-azure-boards-docs) or
[Linear](https://gh.io/cca-linear-docs) to delegate work to Copilot in
one click without leaving your project management tool.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: robgruen <25374553+robgruen@users.noreply.github.com>
CI (`build_ts` / `macos-latest`) was failing because
`ts/packages/defaultAgentProvider/src/mcpAgentProvider.ts` did not pass
the `prettier --check` step.

## Change

Collapsed an over-wrapped `String(...)` call inside a `.map()` callback
to fit on one line as prettier requires:

```ts
// Before
const serverScriptArgs = Object.keys(args).map((k) =>
    String(
        (params.args as Record<string, unknown>)[k],
    ),
);

// After
const serverScriptArgs = Object.keys(args).map((k) =>
    String((params.args as Record<string, unknown>)[k]),
);
```

<!-- START COPILOT CODING AGENT SUFFIX -->



<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> Fix the failing GitHub Actions workflow build_ts (macos-latest, 22)
> Analyze the workflow logs, identify the root cause of the failure, and
implement a fix.
> Job ID: 68271050235
> Job URL:
https://github.com/microsoft/TypeAgent/actions/runs/23463673502/job/68271050235


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

📍 Connect Copilot coding agent with [Jira](https://gh.io/cca-jira-docs),
[Azure Boards](https://gh.io/cca-azure-boards-docs) or
[Linear](https://gh.io/cca-linear-docs) to delegate work to Copilot in
one click without leaving your project management tool.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: robgruen <25374553+robgruen@users.noreply.github.com>
…ld (#2064)

Four TS errors in `agent-dispatcher` were causing `tsc -b` to fail,
blocking the `build_ts` workflow on all platforms.

## Changes

- **`appAgentManager.ts`** — Add missing `loadGrammarRulesNoThrow` to
import from `action-grammar` (used in newly added `loadDynamicGrammar`
for `.agr` format parsing)
- **`appAgentManager.ts`** — Remove duplicate `reloadAgentSchema` method
(TS2393); the new implementation at line 1021 conflicted with the
pre-existing one at line 1233. The private helpers it introduced
(`loadDynamicSchema`, `loadDynamicGrammar`) are retained and already
wired into `updateAction`
- **`configCommandHandlers.ts`** — Register
`ConfigExecutionScriptReuseCommandHandler` in
`configExecutionCommandHandlers` alongside the existing `planReuse`
entry (class was defined but never instantiated)
- **`commandHandlerContext.ts`** — Remove unused
`wrapClientIOWithDisplayLog` helper function (TS6133; never called)

<!-- START COPILOT CODING AGENT SUFFIX -->



<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> Fix the failing GitHub Actions workflow build_ts (windows-latest, 20)
> Analyze the workflow logs, identify the root cause of the failure, and
implement a fix.
> Job ID: 68297257030
> Job URL:
https://github.com/microsoft/TypeAgent/actions/runs/23472219964/job/68297257030


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

📍 Connect Copilot coding agent with [Jira](https://gh.io/cca-jira-docs),
[Azure Boards](https://gh.io/cca-azure-boards-docs) or
[Linear](https://gh.io/cca-linear-docs) to delegate work to Copilot in
one click without leaving your project management tool.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: robgruen <25374553+robgruen@users.noreply.github.com>
…scovery (#2066)

The `shell_and_cli` smoke-test job (windows-latest, Node 22) was failing
because Playwright's `testDir: "./test"` recursively picks up the newly
added `test/partialCompletion/*.spec.ts` Jest unit tests. When
Playwright (ESM) attempts to run them, the CJS-only named export `jest`
from `@jest/globals` is unresolvable, producing:

```
SyntaxError: The requested module '@jest/globals' does not provide an export named 'jest'
```

This is not a PNPM version issue — the `partialCompletion/` tests are
new, so prior PRs never triggered the collision.

## Changes

- **`ts/packages/shell/playwright.config.ts`** — add `testIgnore:
/\/partialCompletion\//` to prevent Playwright from discovering the Jest
unit tests in that subdirectory. Those tests remain covered by
`test:local` (`jest-esm`) in the `build-ts` workflow.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: robgruen <25374553+robgruen@users.noreply.github.com>
@robgruen robgruen deployed to development-fork March 24, 2026 07:17 — with GitHub Actions Active
@robgruen robgruen temporarily deployed to development-fork March 24, 2026 07:17 — with GitHub Actions Inactive
@robgruen robgruen marked this pull request as ready for review March 24, 2026 07:47
@robgruen robgruen added this pull request to the merge queue Mar 24, 2026
Merged via the queue into main with commit 2ea54ca Mar 24, 2026
21 checks passed
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