Skip to content

Conversation

@mattpodwysocki
Copy link
Contributor

@mattpodwysocki mattpodwysocki commented Feb 9, 2026

Summary

This PR provides a better alternative to #110's wildcard export approach. Instead of "./*": "./*" which exposes the entire internal structure, this implements explicit, well-documented subpath exports.

Motivation

Addresses the need from #110 where users want to import parts of this package without the entire server. The wildcard approach in #110 has several drawbacks:

  • Exposes all internal implementation details
  • No control over public API surface
  • Makes it harder to refactor internals without breaking users
  • Not clear what's intended to be public vs private

Solution

Explicit subpath 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 automatically via tshy dual builds.

Usage Examples

Simple: Pre-configured instances

import { directions, searchAndGeocode, isochrone } from '@mapbox/mcp-server/tools';

// Ready to use - no configuration needed
const server = new McpServer({ name: 'my-server', version: '1.0.0' });
directions.installTo(server);

Advanced: Custom HTTP pipeline

import { DirectionsTool } from '@mapbox/mcp-server/tools';
import { httpRequest } from '@mapbox/mcp-server/utils';

const tool = new DirectionsTool({ httpRequest });

Expert: Full customization

import { HttpPipeline, UserAgentPolicy, RetryPolicy } from '@mapbox/mcp-server/utils';
import { DirectionsTool } from '@mapbox/mcp-server/tools';

const pipeline = new HttpPipeline();
pipeline.usePolicy(new UserAgentPolicy('MyApp/2.0.0'));
pipeline.usePolicy(new RetryPolicy(5, 300, 5000));

const tool = new DirectionsTool({ httpRequest: pipeline.execute.bind(pipeline) });

Changes

New Files

  • Barrel exports (src/{tools,resources,prompts,utils}/index.ts) - Clean public APIs
  • Documentation (docs/importing-tools.md) - Comprehensive usage guide with examples
  • Examples (examples/import-example.ts) - Working code demonstrating all patterns
  • Tests (test/exports.test.ts) - Validates all subpath exports work correctly
  • Config (tsconfig.examples.json) - Type checking for examples

Updated Files

  • package.json - Added tshy exports config, updated lint/format scripts to include examples
  • README.md - Added link to importing guide
  • CLAUDE.md - Documented package exports

Benefits Over Wildcard Approach

  1. Explicit API surface - Only exports what's intended to be public
  2. Better discoverability - Clear, documented entry points
  3. Type safety - Full TypeScript support
  4. Tree-shaking friendly - Bundlers can optimize imports better
  5. Future-proof - Can evolve internals without breaking users
  6. Clean names - Instance exports use short names (e.g., directions instead of directionsTool)
  7. Flexible - Three levels of usage (simple, advanced, expert)

Testing

  • ✅ All 611 existing tests pass
  • ✅ New test suite (test/exports.test.ts) validates all subpath exports
  • ✅ Examples included in linting, formatting, and type checking
  • ✅ Documentation includes working, type-checked examples
  • ✅ Both ESM and CommonJS exports verified

Documentation

Comprehensive documentation added in docs/importing-tools.md covering:

  • All usage patterns (simple to expert)
  • Complete API reference
  • Working examples for common scenarios
  • Best practices

Compatibility

  • ✅ Backward compatible - doesn't affect existing usage
  • ✅ Supports both ESM and CommonJS
  • ✅ Works with all bundlers (webpack, rollup, esbuild, vite, etc.)
  • ✅ Full TypeScript support with type definitions

Related

Closes #110 (provides better alternative to wildcard exports)


@vincent-lecrubier-skydio This provides what you need from #110 but with a cleaner, more maintainable approach. You can now import just the tools you need:

import { getCoreTools } from '@mapbox/mcp-server/tools';
import { httpRequest } from '@mapbox/mcp-server/utils';

Let me know if this works for your use case!

mattpodwysocki and others added 7 commits January 12, 2026 16:18
Implements MCP server icons at the correct architectural level (server
initialization) instead of at the tool level. Adds both light and dark
theme variants of the Mapbox logo using base64-encoded SVG data URIs.

- Add mapbox-logo-black.svg for light theme backgrounds
- Add mapbox-logo-white.svg for dark theme backgrounds
- Update server initialization to include icons array with theme property
- Use 800x180 SVG logos embedded as base64 data URIs

This replaces the previous incorrect approach of adding icons to
individual tools, which was not aligned with the MCP specification.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Updates the MCP SDK from 1.25.1 to 1.25.2 and recreates the output
validation patch for the new version. The patch continues to convert
strict output schema validation errors to warnings, allowing tools
to gracefully handle schema mismatches.

Changes:
- Update @modelcontextprotocol/sdk from ^1.25.1 to ^1.25.2
- Recreate SDK patch for version 1.25.2
- Remove obsolete 1.25.1 patch file
- All 397 tests pass with new SDK version

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@mattpodwysocki mattpodwysocki requested a review from a team as a code owner February 9, 2026 16:08
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>
@mattpodwysocki mattpodwysocki force-pushed the feature/explicit-subpath-exports branch from 87b9488 to 9b5e832 Compare February 9, 2026 16:13
ctufts
ctufts previously approved these changes Feb 9, 2026
Resolved conflicts by combining:
- examples paths in format/lint/spellcheck scripts (from feature branch)
- changelog:prepare-release script (from main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants