-
Notifications
You must be signed in to change notification settings - Fork 31
Make package.json export wildcard files too #110
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
base: main
Are you sure you want to change the base?
Make package.json export wildcard files too #110
Conversation
This is needed to allow users to import parts of this package and not then entire server
This PR provides an alternative to #110's wildcard export approach by implementing explicit, well-documented subpath exports that give users direct access to Mapbox MCP components. ## Changes ### Package Exports (via tshy) - `@mapbox/mcp-server/tools` - Tool classes and pre-configured instances - `@mapbox/mcp-server/resources` - Resource classes and instances - `@mapbox/mcp-server/prompts` - Prompt classes and instances - `@mapbox/mcp-server/utils` - HTTP pipeline utilities All exports support both ESM and CommonJS via tshy dual builds. ### New Files - `src/tools/index.ts` - Barrel export for tools with clean instance names - `src/resources/index.ts` - Barrel export for resources - `src/prompts/index.ts` - Barrel export for prompts - `src/utils/index.ts` - Barrel export for HTTP utilities - `docs/importing-tools.md` - Comprehensive usage guide - `examples/import-example.ts` - Working code examples - `test/exports.test.ts` - Test suite validating all exports - `tsconfig.examples.json` - TypeScript config for examples ### Updated Files - `package.json` - Added tshy exports config, updated lint/format scripts - `tsconfig.json` - Added examples reference - `README.md` - Added link to importing guide - `CLAUDE.md` - Documented package exports ### Usage Examples Simple - pre-configured instances: ```typescript import { directions, searchAndGeocode } from '@mapbox/mcp-server/tools'; ``` Advanced - custom tool instances: ```typescript import { DirectionsTool } from '@mapbox/mcp-server/tools'; import { httpRequest } from '@mapbox/mcp-server/utils'; const tool = new DirectionsTool({ httpRequest }); ``` Expert - custom HTTP pipeline: ```typescript import { HttpPipeline, UserAgentPolicy } from '@mapbox/mcp-server/utils'; const pipeline = new HttpPipeline(); pipeline.usePolicy(new UserAgentPolicy('MyApp/1.0')); ``` ## Benefits Over Wildcard Approach 1. **Explicit API surface** - Only exports intended public APIs 2. **Better discoverability** - Clear, documented entry points 3. **Type safety** - Full TypeScript support for all exports 4. **Tree-shaking friendly** - Bundlers can optimize better 5. **Future-proof** - Easy to evolve without breaking changes ## Testing - All 611 existing tests pass - New test suite validates all subpath exports - Examples included in lint/format/type checking - Documentation with working examples Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This PR provides an alternative to #110's wildcard export approach by implementing explicit, well-documented subpath exports that give users direct access to Mapbox MCP components. ## Changes ### Package Exports (via tshy) - `@mapbox/mcp-server/tools` - Tool classes and pre-configured instances - `@mapbox/mcp-server/resources` - Resource classes and instances - `@mapbox/mcp-server/prompts` - Prompt classes and instances - `@mapbox/mcp-server/utils` - HTTP pipeline utilities All exports support both ESM and CommonJS via tshy dual builds. ### New Files - `src/tools/index.ts` - Barrel export for tools with clean instance names - `src/resources/index.ts` - Barrel export for resources - `src/prompts/index.ts` - Barrel export for prompts - `src/utils/index.ts` - Barrel export for HTTP utilities - `docs/importing-tools.md` - Comprehensive usage guide - `examples/import-example.ts` - Working code examples - `test/exports.test.ts` - Test suite validating all exports - `tsconfig.examples.json` - TypeScript config for examples ### Updated Files - `package.json` - Added tshy exports config, updated lint/format scripts - `tsconfig.json` - Added examples reference - `README.md` - Added link to importing guide - `CLAUDE.md` - Documented package exports ### Usage Examples Simple - pre-configured instances: ```typescript import { directions, searchAndGeocode } from '@mapbox/mcp-server/tools'; ``` Advanced - custom tool instances: ```typescript import { DirectionsTool } from '@mapbox/mcp-server/tools'; import { httpRequest } from '@mapbox/mcp-server/utils'; const tool = new DirectionsTool({ httpRequest }); ``` Expert - custom HTTP pipeline: ```typescript import { HttpPipeline, UserAgentPolicy } from '@mapbox/mcp-server/utils'; const pipeline = new HttpPipeline(); pipeline.usePolicy(new UserAgentPolicy('MyApp/1.0')); ``` ## Benefits Over Wildcard Approach 1. **Explicit API surface** - Only exports intended public APIs 2. **Better discoverability** - Clear, documented entry points 3. **Type safety** - Full TypeScript support for all exports 4. **Tree-shaking friendly** - Bundlers can optimize better 5. **Future-proof** - Easy to evolve without breaking changes ## Testing - All 611 existing tests pass - New test suite validates all subpath exports - Examples included in lint/format/type checking - Documentation with working examples Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Hey @vincent-lecrubier-skydio, thanks for opening this PR! Your use case of importing parts of the package without the entire server is definitely valuable. Instead of merging the wildcard export ( What's Available NowYou can now import exactly what you need: // Get the tools registry functions you mentioned
import { getCoreTools } from '@mapbox/mcp-server/tools';
import { httpRequest } from '@mapbox/mcp-server/utils';
// Or import specific tools directly
import { directions, searchAndGeocode } from '@mapbox/mcp-server/tools';
// Or import tool classes for custom instantiation
import { DirectionsTool } from '@mapbox/mcp-server/tools';
import { HttpPipeline, UserAgentPolicy } from '@mapbox/mcp-server/utils';Why Not Wildcard?The wildcard approach ("./": "./") would expose our entire internal structure, making it
Benefits of PR #111
Does This Work for Your Use Case?Could you take a look at PR #111 and let me know if the exposed APIs work for your internal MCP |
Description
This is needed to allow users to import parts of this package and not then entire server
In my case, I want to expose Mapbox MCP internally on my own MCP server, so I don't need the server, but I need
import { getCoreTools } from "@mapbox/mcp-server/dist/esm/tools/toolRegistry.js";This PR allows me to do that. Currently I patch the MCP package.json manually.
Testing
It works and doesn't break anything
Checklist
Additional Notes