|
| 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`, 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 | +### Option 1: VS Code `mcp.json` (Recommended) |
| 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 | +### Option 2: Project `package.json` |
| 32 | + |
| 33 | +Add to your project's `package.json` (used as fallback if no args provided): |
| 34 | + |
| 35 | +```json |
| 36 | +{ |
| 37 | + "sdkContext": { |
| 38 | + "packages": [ |
| 39 | + "@my-scope/my-sdk-package", |
| 40 | + "@other-scope/other-sdk" |
| 41 | + ] |
| 42 | + } |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +## Usage |
| 47 | + |
| 48 | +### CLI (for mcp.json) |
| 49 | + |
| 50 | +```bash |
| 51 | +# Specify packages with --packages flag |
| 52 | +ama-mcp-sdk --packages @my-scope/my-sdk @other-scope/other-sdk |
| 53 | + |
| 54 | +# Show help |
| 55 | +ama-mcp-sdk --help |
| 56 | +``` |
| 57 | + |
| 58 | +### Programmatic (in custom MCP server) |
| 59 | + |
| 60 | +```typescript |
| 61 | +import { registerSdkContextToolAndResources } from '@ama-mcp/sdk'; |
| 62 | + |
| 63 | +// With explicit packages |
| 64 | +await registerSdkContextToolAndResources(server, { |
| 65 | + sdkPackages: ['@my-scope/my-sdk'] |
| 66 | +}); |
| 67 | + |
| 68 | +// Or reads from package.json sdkContext.packages automatically |
| 69 | +await registerSdkContextToolAndResources(server); |
| 70 | +``` |
| 71 | + |
| 72 | +### Available Tool |
| 73 | + |
| 74 | +**`get_sdk_context`** - Retrieve SDK context for configured packages |
| 75 | + |
| 76 | +``` |
| 77 | +// List all configured SDKs with context |
| 78 | +get_sdk_context() |
| 79 | +
|
| 80 | +// Get context for specific package |
| 81 | +get_sdk_context({ packageName: "@my-scope/my-sdk-package" }) |
| 82 | +``` |
| 83 | + |
| 84 | +### Available Resources |
| 85 | + |
| 86 | +**`sdk-context://instructions`** - Usage guidelines for AI assistants |
| 87 | + |
| 88 | +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. |
| 89 | + |
| 90 | +**`sdk-context://<package-name>`** - SDK context for each configured package |
| 91 | + |
| 92 | +Each configured SDK package that has an `SDK_CONTEXT.md` file is exposed as a resource. |
| 93 | + |
| 94 | +## How It Works |
| 95 | + |
| 96 | +1. Reads `sdkContext.packages` from project's `package.json` or uses CLI arguments |
| 97 | +2. Uses Node.js `require.resolve()` to automatically locate packages |
| 98 | +3. Loads `SDK_CONTEXT.md` from each resolved package |
| 99 | +4. Registers each as an MCP resource |
| 100 | +5. Provides a tool for AI assistants to query SDK information |
| 101 | + |
| 102 | +## Package Resolution |
| 103 | + |
| 104 | +The SDK automatically discovers packages using Node.js's `require.resolve()`. This means: |
| 105 | + |
| 106 | +- **No manual path configuration needed** - packages are found automatically |
| 107 | +- **Works with workspaces** - supports npm/yarn/pnpm workspace configurations |
| 108 | +- **Flexible installation** - works with local, global, or custom module paths |
| 109 | +- **Error handling** - clear error messages when packages aren't found |
| 110 | + |
| 111 | +If a package isn't found, ensure: |
| 112 | +1. The package is installed (`npm install <package-name>`) |
| 113 | +2. The package name is spelled correctly |
| 114 | +3. The package has an `SDK_CONTEXT.md` file in its root |
| 115 | + |
| 116 | +**Security**: The system validates package names to prevent path traversal attacks and only accepts valid npm package name patterns. |
| 117 | + |
| 118 | +## Troubleshooting |
| 119 | + |
| 120 | +### Package Not Found |
| 121 | +``` |
| 122 | +Package "@my-scope/my-sdk" not found. Is it installed? |
| 123 | +``` |
| 124 | +**Solution**: Install the package or verify the name in your configuration. |
| 125 | + |
| 126 | +### No SDK_CONTEXT.md Found |
| 127 | +``` |
| 128 | +No SDK_CONTEXT.md found for @my-scope/my-sdk |
| 129 | +``` |
| 130 | +**Solution**: Generate the context file using the command below. |
| 131 | + |
| 132 | +## Generating SDK Context |
| 133 | + |
| 134 | +SDK maintainers can generate `SDK_CONTEXT.md` using: |
| 135 | + |
| 136 | +```bash |
| 137 | +cd /path/to/sdk-project |
| 138 | +npx amasdk-update-sdk-context --interactive |
| 139 | +``` |
0 commit comments