# Use the AstroNode MCP server from the OpenAI Agents SDK

> The TypeScript Agents SDK turns each MCP tool into an ordinary function tool on your agent. One `MCPServerStreamableHttp` object with your key in `requestInit` is the whole integration; the details worth knowing are how it rewrites schemas and what it hands the model.

Source: https://astronode.dev/integrations/mcp-openai-agents · Updated: 2026-12-05

**How this page was verified:** Run on 5 December 2026 with `@openai/agents` 0.23.1 on Node 24, against the AstroNode API running in memory behind the same MCP server code that is hosted (local HTTP and the stdio build). Executed through the SDK's own objects: connecting `MCPServerStreamableHttp` and `MCPServerStdio`, listing tools with `getAllMcpTools` (128, and 12 with `?groups=`), invoking the converted `charts_birth` function tool (ascendant Virgo 19.76 degrees), the error cases shown, `toolFilter`, `includeServerInToolNames` and both settings of `convertSchemasToStrict`. Not executed: any model call. The `Agent` + `run()` program and the `hostedMcpTool` variant were type-checked with `tsc --noEmit` in strict mode but never run, because no OpenAI key was used; the hosted variant also needs a server OpenAI can reach, which a local test server is not.

## Connect and run an agent

Install `@openai/agents` and `zod` (a peer dependency); the MCP client it uses, `@modelcontextprotocol/client` (2.4.0 here), is an optional dependency that npm installs with it. `MCPServerStreamableHttp` takes the URL plus `requestInit`, which is passed to `fetch` for every request, so the `Authorization` header goes there. The agent does not open or close the connection for you; the SDK's own types say to call `connect()` before handing the server to an agent and `close()` when done:

Type-checked (strict); the model call was not executed. Set ASTRONODE_API_KEY (aie_live_... or aie_test_...) and OPENAI_API_KEY.

```typescript
import { Agent, MCPServerStreamableHttp, run } from "@openai/agents";

const astronode = new MCPServerStreamableHttp({
  name: "astronode",
  url: "https://mcp.astronode.dev/mcp?groups=charts,dasha,panchang,muhurta",
  requestInit: { headers: { Authorization: `Bearer ${process.env.ASTRONODE_API_KEY}` } },
  cacheToolsList: true,
});

await astronode.connect();
try {
  const agent = new Agent({
    name: "Astrologer",
    instructions:
      "Answer astrology questions with the AstroNode tools. Never estimate a position: call a tool. " +
      "tz_offset_minutes is the UTC offset in force at the birth, in minutes (India: 330).",
    mcpServers: [astronode],
  });
  const result = await run(
    agent,
    "What is my ascendant? I was born on 24 April 1973 at 5:25 pm in Mumbai.",
  );
  console.log(result.finalOutput);
} finally {
  await astronode.close();
}
```

`cacheToolsList: true` is safe here: the tool list for a given URL changes only when the server is redeployed. Without it the SDK lists tools again on every run. Listing is free; see [the MCP server page](https://astronode.dev/mcp) for what a call costs. The server is stateless, so `astronode.sessionId` stays `undefined` - nothing to resume or persist between runs.

If the server cannot be reached, `connect()` throws (`SdkError: Version negotiation probe failed: fetch failed` against a closed port) and logs `Error initializing MCP server`. For several servers, the SDK's `connectMcpServers` returns the healthy ones in `active` instead of throwing.

## Call charts_birth without a model

`getAllMcpTools` returns exactly the function tools the agent would send to the model, and each has an `invoke(runContext, jsonString)` method. That makes it easy to test the wiring before spending model tokens. This is the script that ran:

```typescript
import { MCPServerStreamableHttp, getAllMcpTools, RunContext } from "@openai/agents";

const astronode = new MCPServerStreamableHttp({
  name: "astronode",
  url: "https://mcp.astronode.dev/mcp?groups=charts,dasha,panchang,muhurta",
  requestInit: { headers: { Authorization: `Bearer ${process.env.ASTRONODE_API_KEY}` } },
  cacheToolsList: true,
});

await astronode.connect();
try {
  const tools = await getAllMcpTools({ mcpServers: [astronode] });
  console.log(tools.length, tools.map((t) => t.name).join(", "));

  const chartsBirth = tools.find((t) => t.name === "charts_birth");
  if (chartsBirth?.type !== "function") throw new Error("charts_birth not offered");
  const output = await chartsBirth.invoke(
    new RunContext(),
    JSON.stringify({ date: "1973-04-24", time: "17:25", tz_offset_minutes: 330, lat: 19.076, lng: 72.8777 }),
  );
  console.log(output);
} finally {
  await astronode.close();
}
```

Output, shortened. The full text is 1,559 characters.

```text
12 charts_birth, charts_varga, dasha_char, dasha_lookup, dasha_vimshottari, dasha_yogini, gowri_nalla_neram, muhurta_auspicious, muhurta_choghadiya, muhurta_hora, muhurta_inauspicious, panchang
{
  type: 'text',
  text: '{"request_id":"req_01M92P...","data":{"ascendant":{"sign":"Virgo","degree":19.759582224440123},"planets":[{"name":"Sun","sign":"Aries","house":8,...'
}
```

The result is not a parsed object. When the MCP result has a single content item, the SDK returns that item as is - `{ type: "text", text }` - and the `text` is the API's JSON envelope (`request_id`, `data`, `meta`). In that run `data.ascendant` was Virgo at 19.76 degrees, and the Moon was in Sagittarius, 26.79 degrees, Uttara Ashadha pada 1, house 4. To read figures in your own code, `JSON.parse(output.text)`. The model receives the same text.

## How the SDK converts the tool list

Each MCP tool becomes a function tool with the same name, the server's description (which ends with the plan it needs) and the server's JSON Schema as `parameters`. What happens to the schema depends on `mcpConfig.convertSchemasToStrict` on the `Agent` (default off). Observed on this server's 128 tools:

*From getAllMcpTools against the local server. The warning appears on every conversion even with strict off; it is noise, not a failure.*

| Tool | Default (strict off) | convertSchemasToStrict: true |
| --- | --- | --- |
| `charts_birth` and the other 109 closed schemas | `strict: false`; the top-level `additionalProperties: false` is rewritten to `true` | `strict: true`; optional `interpretation` becomes required and nullable |
| `dasha_lookup` and 17 more with open objects (numerology, synastry, composite, `vastu_analyze`) | `strict: false`, schema kept; one `Error converting MCP schema to strict mode` warning each | Same - the SDK falls back to non-strict and logs the warning |

**Either setting works.** In strict mode OpenAI models must send every property, so an argument you did not want arrives as `null` - at the top level (`"interpretation": null`) and inside objects. The server treats `null` on an optional argument as not set and drops it before validating, so the call is the one the model meant. Version 0.1.0 of the server did not, and rejected those calls with `data/interpretation must be object`; the hosted server and `@astronode/mcp` 0.1.1 accept them. A `null` on a required argument is still an error. With strict off, a stray argument is rejected by the server (`data must NOT have additional properties`), but the model only sends one by mistake, and it sees the message.

The SDK keeps the server's tool names unchanged (`charts_birth` stays `charts_birth`). If you combine several MCP servers that might share a name, set `mcpConfig: { includeServerInToolNames: true }`: the model then sees `mcp_astronode__charts_birth`, and the SDK still calls `charts_birth` on the server.

## 128 tools in one request

No hard tool limit is documented for the Responses API, which the SDK uses by default: the installed `openai` types state a 128 cap only for Assistants and eval runs. But OpenAI's function-calling guide says to aim for fewer than 20 functions at the start of a turn, and every definition is sent and billed as input on every model call. Measured as the SDK serialises them, the full list is about 125,000 characters of JSON; the four groups above are 10,000.

Narrow on the server, not in the SDK. `?groups=` on the URL (or `?tools=charts_birth,dasha_vimshottari`) means the server only lists those tools. The SDK's own `toolFilter: createMCPToolStaticFilter({ allowed: [...] })` also works - `getAllMcpTools` returned 2 tools - but `listTools()` on the same object still returned all 128, so the full list still crosses the wire. Group names are on [the MCP server page](https://astronode.dev/mcp).

## Errors the model sees

A tool error does not throw inside `run()`. The server marks the result `isError: true`, but the SDK passes only the text on as the tool output, so the model reads the message and can correct itself or explain. From the runs:

| Cause | What `invoke` returned |
| --- | --- |
| `date: "24/04/1973"` | `Input validation error: Invalid arguments for tool charts_birth: data/date must match pattern "^\d{4}-\d{2}-\d{2}$"` |
| No `Authorization` header | `No AstroNode API key was provided, so this tool cannot run. Remote server: send the header ...` (tools still listed: 128) |
| Arguments that are not JSON | `An error occurred while running the tool.` - the SDK's default error function |

A missing key therefore fails at the first tool call, not at `connect()`. Check the key before the run starts if you would rather fail early. To have SDK-side failures throw instead of reaching the model, pass `errorFunction: null` to the server; malformed JSON then threw `InvalidToolInputError`.

## Local server over stdio

```typescript
import { MCPServerStdio } from "@openai/agents";

const astronode = new MCPServerStdio({
  name: "astronode",
  command: "npx",
  args: ["-y", "@astronode/mcp"],
  env: { ASTRONODE_API_KEY: process.env.ASTRONODE_API_KEY!, ASTRONODE_MCP_GROUPS: "charts,dasha" },
});
await astronode.connect(); // starts the process; close() stops it
```

Pass it in `mcpServers` exactly like the HTTP server. The same server, built from source and started with `node`, listed 6 tools for `charts,dasha` and returned the same Virgo ascendant. The narrowing variable is `ASTRONODE_MCP_GROUPS` here, since there is no URL.

## hostedMcpTool: OpenAI calls the server

The SDK has a second route. `hostedMcpTool` does not connect from your process at all: it adds an MCP tool to the Responses API request, and OpenAI's servers list and call `mcp.astronode.dev` themselves. Your key travels in that request to OpenAI, which sends it on to AstroNode; with the classes above it goes straight from your process to AstroNode.

Type-checked only - this needs an OpenAI key and a server OpenAI can reach, so it was not run.

```typescript
import { Agent, hostedMcpTool } from "@openai/agents";

const agent = new Agent({
  name: "Astrologer",
  instructions: "Answer astrology questions with the AstroNode tools.",
  tools: [
    hostedMcpTool({
      serverLabel: "astronode",
      serverUrl: "https://mcp.astronode.dev/mcp",
      headers: { Authorization: `Bearer ${process.env.ASTRONODE_API_KEY}` },
      allowedTools: ["charts_birth", "dasha_vimshottari", "panchang"],
      requireApproval: "never",
    }),
  ],
});
```

Here `allowedTools` replaces `toolFilter`, and `requireApproval` decides whether each call pauses for your approval; the calculation tools are read-only, so `"never"` is reasonable. Choose it to save a round trip through your process, and avoid it when you need to see or log each call locally, or when you run the server on localhost or a private network.

> **Note:** The Python Agents SDK has equivalent MCP server classes; this page covers only the TypeScript package, which is what was tested.

## Questions

**Which AstroNode endpoints does the OpenAI Agents SDK example call?**

1 endpoint: Birth Chart (Kundli) (`POST /v1/charts/birth`).

**Was the OpenAI Agents SDK code on this page actually run?**

Run on 5 December 2026 with `@openai/agents` 0.23.1 on Node 24, against the AstroNode API running in memory behind the same MCP server code that is hosted (local HTTP and the stdio build). Executed through the SDK's own objects: connecting `MCPServerStreamableHttp` and `MCPServerStdio`, listing tools with `getAllMcpTools` (128, and 12 with `?groups=`), invoking the converted `charts_birth` function tool (ascendant Virgo 19.76 degrees), the error cases shown, `toolFilter`, `includeServerInToolNames` and both settings of `convertSchemasToStrict`. Not executed: any model call. The `Agent` + `run()` program and the `hostedMcpTool` variant were type-checked with `tsc --noEmit` in strict mode but never run, because no OpenAI key was used; the hosted variant also needs a server OpenAI can reach, which a local test server is not.

## Endpoints

- [`POST /v1/charts/birth`](https://astronode.dev/capabilities/vedic/charts-birth) - Birth Chart (Kundli) API
