Commit 9b5e832
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
- docs
- examples
- src
- prompts
- resources
- tools
- utils
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
0 commit comments