Skip to content

Commit 9b5e832

Browse files
Add explicit subpath exports for tools, resources, prompts, and utils
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>
1 parent 04a1930 commit 9b5e832

12 files changed

Lines changed: 1132 additions & 6 deletions

File tree

CLAUDE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,15 @@ npx plop create-tool "Search" "search_tool"
9494
- **Detailed Standards**: See docs/engineering_standards.md for complete guidelines
9595
- **Tracing Setup**: See docs/tracing.md for OpenTelemetry configuration
9696
- **Integration Guides**: See docs/ for Claude Desktop, VS Code, Cursor, and Goose setup
97+
- **Direct Imports**: See docs/importing-tools.md for using tools/resources/prompts in your own applications
98+
99+
## Package Exports
100+
101+
The package provides subpath exports for direct integration without running the MCP server:
102+
103+
- `@mapbox/mcp-server/tools` - Tool classes and pre-configured instances
104+
- `@mapbox/mcp-server/resources` - Resource classes and instances
105+
- `@mapbox/mcp-server/prompts` - Prompt classes and instances
106+
- `@mapbox/mcp-server/utils` - HTTP pipeline utilities (httpRequest, HttpPipeline, policies)
107+
108+
All exports support both ESM and CommonJS via tshy dual builds.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ For detailed setup instructions for different integrations, refer to the followi
5151
- [VS Code Setup](./docs/vscode-setup.md) - Setting up a development environment in Visual Studio Code
5252
- [Cursor AI IDE Setup](./docs/cursor-setup.md) - Setting up a development environment in Cursor AI IDE
5353
- [Smolagents Integration](./docs/using-mcp-with-smolagents/README.md) - Example showing how to connect Smolagents AI agents to Mapbox's tools
54+
- **[Importing Tools Directly](./docs/importing-tools.md)** - Use Mapbox tools in your own applications without running the MCP server
5455

5556
## Example Prompts
5657

0 commit comments

Comments
 (0)