LearnNewsExamplesServices
Frontmatter
id7951
titleEnhance MCP Client with Connection State and Env Validation
stateClosed
labels
enhancementai
assigneestobiu
createdAtNov 30, 2025, 4:22 PM
updatedAtNov 30, 2025, 4:31 PM
githubUrlhttps://github.com/neomjs/neo/issues/7951
authortobiu
commentsCount1
parentIssue7931
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtNov 30, 2025, 4:31 PM

Enhance MCP Client with Connection State and Env Validation

Closed v11.14.0 enhancementai
tobiu
tobiu commented on Nov 30, 2025, 4:22 PM

Context

A recent architectural review suggested improvements to the Neo.ai.mcp.client.Client configuration and state management.

Goal

Enhance the MCP Client with connection state tracking and environment variable validation to improve robustness and developer experience.

Requirements

  1. Connection State: Add a connected config to Client.mjs.
    • Type: Non-reactive config (class field or config without underscore, unless we identify a need for reactivity later).
    • Logic: Set to true after successful connection in initAsync. Set to false in close.
    • Benefit: Allows agents to check connection status before attempting operations.
  2. Environment Validation: Add requiredEnv support to ai/mcp/client/config.mjs and Client.mjs.
    • Config: Update ClientConfig schema (conceptually) to support a requiredEnv: String[] array in the server definition.
    • Validation: In Client.mjs initAsync, check if the defined required environment variables exist in the env object (or process.env). Throw a descriptive error if any are missing before attempting to spawn the server process.
    • Benefit: Fail-fast with clear error messages instead of cryptic spawn failures.

Deliverables

  • Updated ai/mcp/client/Client.mjs.
  • Updated ai/mcp/client/config.mjs (example/default config to include required envs for our servers, e.g., GH_TOKEN).
tobiu added the enhancement label on Nov 30, 2025, 4:22 PM
tobiu added the ai label on Nov 30, 2025, 4:22 PM
tobiu added parent issue #7931 on Nov 30, 2025, 4:22 PM
tobiu assigned to @tobiu on Nov 30, 2025, 4:22 PM
tobiu referenced in commit 5966472 - "Enhance MCP Client with Connection State and Env Validation #7951" on Nov 30, 2025, 4:31 PM
tobiu
tobiu Nov 30, 2025, 4:31 PM

Input from Gemini 2.5 pro:

✦ I have successfully implemented connection state tracking and environment validation in Neo.ai.mcp.client.Client.

Changes

  1. Configuration: Updated ai/mcp/client/config.mjs to include requiredEnv for our default servers (GH_TOKEN, GEMINI_API_KEY).
  2. Client Enhancement:
    • Added connected state (boolean).
    • Added requiredEnv config.
    • Updated initAsync to validate requiredEnv against this.env (and process.env fallback) before connection.
    • Updated initAsync to set connected = true on success.
    • Updated close to set connected = false.
    • Updated callTool and listTools to throw if !connected.

Verification

Ran mcp-demo-agent.mjs. It connected successfully, indicating the environment checks passed (my environment has the keys). The agent output confirms the clients are operational. I verified the new state properties in the debug log.

I am ready to close this ticket.

tobiu closed this issue on Nov 30, 2025, 4:31 PM