Skip to content

Commit bee794e

Browse files
mojobeepingdcramercodex
authored
fix: keep stdio transport types self-contained (#1063)
## Summary Make the public `@sentry/mcp-server/transports/stdio` declaration self-contained by exporting a local `StdioServerContext` type instead of leaking the private workspace-only `@sentry/mcp-core/types` package. ## Reproduction With the published `@sentry/mcp-server@0.35.0`, a clean TypeScript consumer of the public stdio subpath fails: ```text node_modules/@sentry/mcp-server/dist/transports/stdio.d.ts(2,31): error TS2307: Cannot find module '@sentry/mcp-core/types' or its corresponding type declarations. ``` The runtime bundle is self-contained, but the emitted declaration still imports the private `@sentry/mcp-core` workspace package that consumers do not receive. ## Validation - `pnpm --filter @sentry/mcp-core build` - `pnpm --filter @sentry/mcp-server tsc` - `pnpm --filter @sentry/mcp-server build` - `pnpm pack --pack-destination /Users/aliou/Desktop/MakeMoney/tmp` - Clean consumer install of the patched tarball plus `typescript@latest` - `npx tsc --noEmit` - `node -e "import('@sentry/mcp-server/transports/stdio').then(m=>console.log(typeof m.startStdio))"` - `git diff --check` --------- Co-authored-by: Mojo <291533947+mojobeeping@users.noreply.github.com> Co-authored-by: David Cramer <dcramer@gmail.com> Co-authored-by: Codex <codex@openai.com>
1 parent 69c9ffb commit bee794e

2 files changed

Lines changed: 132 additions & 4 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: MCP Server Package
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
paths:
8+
- ".github/workflows/mcp-server-package.yml"
9+
- "packages/mcp-core/**"
10+
- "packages/mcp-server/**"
11+
- "packages/mcp-server-tsconfig/**"
12+
- "package.json"
13+
- "pnpm-lock.yaml"
14+
- "pnpm-workspace.yaml"
15+
- "turbo.json"
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
package-consumer:
22+
name: Clean Consumer Typecheck
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: "20"
32+
33+
# pnpm/action-setup@v4
34+
- uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda
35+
name: Install pnpm
36+
with:
37+
run_install: false
38+
39+
- name: Get pnpm store directory
40+
shell: bash
41+
run: |
42+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
43+
44+
- uses: actions/cache@v4
45+
name: Setup pnpm cache
46+
with:
47+
path: ${{ env.STORE_PATH }}
48+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
49+
restore-keys: |
50+
${{ runner.os }}-pnpm-store-
51+
52+
- name: Install dependencies
53+
run: pnpm install --frozen-lockfile
54+
55+
- name: Build package dependencies
56+
run: pnpm --filter @sentry/mcp-core build
57+
58+
- name: Build stdio package
59+
run: pnpm --filter @sentry/mcp-server build
60+
61+
- name: Pack stdio package
62+
run: pnpm --dir packages/mcp-server pack --pack-destination "$RUNNER_TEMP"
63+
64+
- name: Typecheck clean consumer
65+
shell: bash
66+
run: |
67+
set -euo pipefail
68+
69+
consumer="$RUNNER_TEMP/mcp-server-consumer"
70+
mkdir -p "$consumer"
71+
cd "$consumer"
72+
73+
export npm_config_cache="$RUNNER_TEMP/npm-cache"
74+
cat > package.json <<'EOF'
75+
{
76+
"private": true,
77+
"type": "module"
78+
}
79+
EOF
80+
81+
npm install --ignore-scripts --no-audit --no-fund "$RUNNER_TEMP"/sentry-mcp-server-*.tgz typescript@^5.8.3 @types/node@^22
82+
83+
cat > tsconfig.json <<'EOF'
84+
{
85+
"compilerOptions": {
86+
"module": "NodeNext",
87+
"moduleResolution": "NodeNext",
88+
"noEmit": true,
89+
"strict": true,
90+
"target": "ES2022"
91+
},
92+
"include": ["index.ts"]
93+
}
94+
EOF
95+
96+
cat > index.ts <<'EOF'
97+
import {
98+
startStdio,
99+
type StdioServerContext,
100+
} from "@sentry/mcp-server/transports/stdio";
101+
102+
declare const server: Parameters<typeof startStdio>[0];
103+
104+
const telemetryContext: StdioServerContext = {
105+
agentMode: false,
106+
experimentalMode: false,
107+
mcpUrl: "https://example.com/mcp",
108+
sentryHost: "sentry.io",
109+
};
110+
111+
void startStdio(server, telemetryContext);
112+
void startStdio(server, {
113+
accessToken: "token",
114+
constraints: {},
115+
sentryHost: "sentry.io",
116+
});
117+
EOF
118+
119+
npx tsc --noEmit

‎packages/mcp-server/src/transports/stdio.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2020
* ```
2121
*/
2222
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
23-
import type { ServerContext } from "@sentry/mcp-core/types";
2423
import { LIB_VERSION } from "@sentry/mcp-core/version";
2524
import * as Sentry from "@sentry/node";
2625

26+
export type StdioServerContext = {
27+
sentryHost?: string;
28+
mcpUrl?: string;
29+
agentMode?: boolean;
30+
experimentalMode?: boolean;
31+
};
32+
2733
function getStdioSpanAttributes(
28-
context: ServerContext,
34+
context: StdioServerContext,
2935
): Record<string, string | boolean> {
3036
const attributes: Record<string, string | boolean> = {
3137
"app.transport": "stdio",
@@ -54,7 +60,7 @@ function getStdioSpanAttributes(
5460
* All operations are wrapped in Sentry tracing for observability.
5561
*
5662
* @param server - Configured and instrumented MCP server instance (with context in closures)
57-
* @param context - Server context with authentication and configuration (for telemetry attributes)
63+
* @param context - Context values used for telemetry attributes
5864
*
5965
* @example CLI Integration
6066
* ```typescript
@@ -73,7 +79,10 @@ function getStdioSpanAttributes(
7379
* await startStdio(server, context);
7480
* ```
7581
*/
76-
export async function startStdio(server: McpServer, context: ServerContext) {
82+
export async function startStdio<Context extends StdioServerContext>(
83+
server: McpServer,
84+
context: Context,
85+
) {
7786
await Sentry.startNewTrace(async () => {
7887
return await Sentry.startSpan(
7988
{

0 commit comments

Comments
 (0)