-
Notifications
You must be signed in to change notification settings - Fork 60
feat: compile example servers to JavaScript for npm consumption #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jerome3o-anthropic
wants to merge
18
commits into
main
Choose a base branch
from
jerome/compile-examples-to-js
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add TypeScript compilation for server code so the example packages can be
imported and used by consumers without requiring TypeScript compilation.
Changes:
- Add tsconfig.server.json to each example for compiling server code
- Update package.json exports to point to compiled dist/server/server.js
- Add types field pointing to dist/server/server.d.ts
- Update build scripts to include server compilation step
- Fix .ts import extensions to .js in customer-segmentation-server
This enables importing the createServer function from published packages:
import { createServer } from '@modelcontextprotocol/server-basic-react';
@modelcontextprotocol/ext-apps
@modelcontextprotocol/server-basic-react
@modelcontextprotocol/server-basic-vanillajs
@modelcontextprotocol/server-budget-allocator
@modelcontextprotocol/server-cohort-heatmap
@modelcontextprotocol/server-customer-segmentation
@modelcontextprotocol/server-map
@modelcontextprotocol/server-pdf
@modelcontextprotocol/server-scenario-modeler
@modelcontextprotocol/server-shadertoy
@modelcontextprotocol/server-sheet-music
@modelcontextprotocol/server-system-monitor
@modelcontextprotocol/server-threejs
@modelcontextprotocol/server-transcript
@modelcontextprotocol/server-video-resource
@modelcontextprotocol/server-wiki-explorer
commit: |
- server.ts: exports createServer() only (library entry point)
- main.ts: entry point with main() that runs the server (binary)
- package.json: adds bin field for npx support, uses inline bun build
- tsconfig.server.json: emitDeclarationOnly, outputs to dist/
This allows:
1. Importing the server as a library: import { createServer } from '@modelcontextprotocol/server-basic-react'
2. Running with npx: npx @modelcontextprotocol/server-basic-react [--stdio]
Added migration script at scripts/migrate-server-examples.ts
Apply the same refactoring to all 13 remaining server examples: - scenario-modeler-server, shadertoy-server, map-server - cohort-heatmap-server, customer-segmentation-server, video-resource-server - system-monitor-server, budget-allocator-server, sheet-music-server - threejs-server, integration-server, transcript-server, wiki-explorer-server Each now has: - server.ts: exports createServer() (library) - main.ts: runs the server (binary with shebang) - bin field in package.json for npx support
Collaborator
|
@jerome3o-anthropic I took the liberty to refactor things:
Also @jonathanhefner FYI :-) |
ochafik
previously approved these changes
Jan 13, 2026
…externals - Remove 'chmod +x dist/index.js' which doesn't exist on Windows - Add '--external ./server.js' to prevent bun from treating the import as a second entry point
- Change import from './server.js' to './server.ts' in main.ts files - Remove --external flag since bun should inline everything - Fixes Windows build where bun couldn't resolve .js to .ts properly
Bun on Windows incorrectly treats imported .ts files as entry points. Use --external './server.js' to work around this, creating a runtime dependency between index.js and server.js.
- Added pdf-server example from main - Refactored to library/binary structure like other examples - server.ts exports createServer() and initializePdfIndex() - main.ts is the CLI entry point - Removed server-utils.ts (inlined into main.ts)
The literal path --external ./server.js was not matching the import. Using glob pattern --external "./server*" correctly externalizes the server module.
The "./server*" pattern was not matching on Windows. Using "*/server.js" matches any path ending in /server.js which works cross-platform.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add TypeScript compilation for server code so example packages can be imported by consumers without requiring TypeScript compilation.
Changes
tsconfig.server.jsonto each example for compiling server code to JavaScriptpackage.jsonexports to point to compileddist/server/server.jstypesfield pointing todist/server/server.d.tstsc -p tsconfig.server.json).tsimport extensions to.jsin customer-segmentation-serverUsage
After this change, consumers can import the
createServerfunction from published packages:Note
Some examples have pre-existing build issues (vue/svelte/preact missing types, map-server type error) that are not related to this PR. The server compilation itself works correctly.