|
| 1 | +# @ama-mcp/sdk |
| 2 | + |
| 3 | +MCP module to expose `SDK_CONTEXT.md` from installed packages to AI assistants. |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +When SDKs are generated using [@ama-sdk/schematics](https://www.npmjs.com/package/@ama-sdk/schematics), they can include an `SDK_CONTEXT.md` file that describes: |
| 8 | +- Available API domains and operations |
| 9 | +- Models used by each domain |
| 10 | +- Guidelines for AI tools to avoid hallucinations |
| 11 | + |
| 12 | +This MCP module automatically discovers and loads these context files from installed packages using Node.js's module resolution, then exposes them to AI assistants. |
| 13 | + |
| 14 | +## Configuration |
| 15 | + |
| 16 | +### VS Code `.vscode/mcp.json` |
| 17 | + |
| 18 | +Configure SDK packages directly in your `.vscode/mcp.json`: |
| 19 | + |
| 20 | +```json |
| 21 | +{ |
| 22 | + "servers": { |
| 23 | + "sdk-context": { |
| 24 | + "command": "npx", |
| 25 | + "args": ["ama-mcp-sdk", "--packages", "@my-scope/my-sdk-package", "@other-scope/other-sdk"] |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +### CLI (for mcp.json) |
| 34 | + |
| 35 | +```bash |
| 36 | +# Specify packages with --packages flag |
| 37 | +ama-mcp-sdk --packages @my-scope/my-sdk @other-scope/other-sdk |
| 38 | + |
| 39 | +# Show help |
| 40 | +ama-mcp-sdk --help |
| 41 | +``` |
| 42 | + |
| 43 | +### Programmatic (in custom MCP server) |
| 44 | + |
| 45 | +```typescript |
| 46 | +import { registerSdkContextToolAndResources } from '@ama-mcp/sdk'; |
| 47 | + |
| 48 | +// With explicit packages |
| 49 | +await registerSdkContextToolAndResources(server, { |
| 50 | + sdkPackages: ['@my-scope/my-sdk'] |
| 51 | +}); |
| 52 | + |
| 53 | +// Or reads from package.json sdkContext.packages automatically |
| 54 | +await registerSdkContextToolAndResources(server); |
| 55 | +``` |
| 56 | + |
| 57 | +### Available Tool |
| 58 | + |
| 59 | +**`get_sdk_context`** - Retrieve SDK context for configured packages |
| 60 | + |
| 61 | +``` |
| 62 | +// List all configured SDKs with context |
| 63 | +get_sdk_context() |
| 64 | +
|
| 65 | +// Get context for specific package |
| 66 | +get_sdk_context({ packageName: "@my-scope/my-sdk-package" }) |
| 67 | +``` |
| 68 | + |
| 69 | +### Available Resources |
| 70 | + |
| 71 | +**`sdk-context://instructions`** - Usage guidelines for AI assistants |
| 72 | + |
| 73 | +This resource provides instructions on how to use SDK context effectively to avoid hallucinations when implementing features. AI assistants should read this resource before using the `get_sdk_context` tool. |
| 74 | + |
| 75 | +**`sdk-context://<package-name>`** - SDK context for each configured package |
| 76 | + |
| 77 | +Each configured SDK package that has an `SDK_CONTEXT.md` file is exposed as a resource. |
| 78 | + |
| 79 | +## How It Works |
| 80 | + |
| 81 | +1. Reads `sdkContext.packages` from project's `package.json` or uses CLI arguments |
| 82 | +2. Uses Node.js `require.resolve()` to automatically locate packages |
| 83 | +3. Loads `SDK_CONTEXT.md` from each resolved package |
| 84 | +4. Registers each as an MCP resource |
| 85 | +5. Provides a tool for AI assistants to query SDK information |
| 86 | + |
| 87 | +## Package Resolution |
| 88 | + |
| 89 | +The SDK automatically discovers packages using Node.js's `require.resolve()`. This means: |
| 90 | + |
| 91 | +- **No manual path configuration needed** - packages are found automatically |
| 92 | +- **Works with workspaces** - supports npm/yarn/pnpm workspace configurations |
| 93 | +- **Flexible installation** - works with local, global, or custom module paths |
| 94 | +- **Error handling** - clear error messages when packages aren't found |
| 95 | + |
| 96 | +If a package isn't found, ensure: |
| 97 | +1. The package is installed (`npm install <package-name>`) |
| 98 | +2. The package name is spelled correctly |
| 99 | +3. The package has an `SDK_CONTEXT.md` file in its root |
| 100 | + |
| 101 | +**Security**: The system validates package names to prevent path traversal attacks and only accepts valid npm package name patterns. |
| 102 | + |
| 103 | +## Troubleshooting |
| 104 | + |
| 105 | +### Package Not Found |
| 106 | +``` |
| 107 | +Package "@my-scope/my-sdk" not found. Is it installed? |
| 108 | +``` |
| 109 | +**Solution**: Install the package or verify the name in your configuration. |
| 110 | + |
| 111 | +### No SDK_CONTEXT.md Found |
| 112 | +``` |
| 113 | +No SDK_CONTEXT.md found for @my-scope/my-sdk |
| 114 | +``` |
| 115 | +**Solution**: Generate the context file using the command below. |
| 116 | + |
| 117 | +## Generating SDK Context |
| 118 | + |
| 119 | +SDK maintainers can generate `SDK_CONTEXT.md` using: |
| 120 | + |
| 121 | +```bash |
| 122 | +cd /path/to/sdk-project |
| 123 | +npx amasdk-update-sdk-context --interactive |
| 124 | +``` |
0 commit comments