Implementation:1mcp app Agent importPolicy
| Knowledge Sources | |
|---|---|
| Domains | Testing, Software_Architecture |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete static analyzer that enforces the SDK import boundary by detecting legacy `@modelcontextprotocol/sdk` imports outside the designated `src/sdk/legacy/` directory.
Description
The importPolicy module is a static analysis tool that parses all TypeScript source files in `src/` using the TypeScript AST parser and identifies imports of the legacy MCP SDK (`@modelcontextprotocol/sdk`) that occur outside the `src/sdk/legacy/` boundary. Violations are reported with file path, line number, and the specific import statement. The tool is run as part of `pnpm check` and CI to prevent legacy SDK contamination of modern code paths.
Usage
Import this module when you need to:
- Check for legacy SDK import violations in the codebase
- Enforce the SDK boundary as a build-time or CI gate
- Format import violations for human-readable output
Code Reference
Source Location
- Repository: 1MCP Agent
- File: scripts/sdk-boundary/import-policy.mjs (L44-153)
Signature
export function findLegacySdkImports(
sourceText: string,
filePath: string,
): Violation[];
export async function checkSdkImportBoundary(
root: string,
): Promise<Report>;
export function formatImportViolations(
violations: Violation[],
): string;
Import
import { findLegacySdkImports, checkSdkImportBoundary } from './import-policy.mjs';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| sourceText | string | Yes | File source code |
| filePath | string | Yes | Relative file path |
| root | string | Yes | Repository root |
Outputs
| Name | Type | Description |
|---|---|---|
| Violation[] | array | List of import violations with file, line, import text |
| Report | object | Summary with violation count and details |
Usage Examples
Check SDK Boundary
import { checkSdkImportBoundary } from './import-policy.mjs';
const report = await checkSdkImportBoundary('/path/to/repo');
if (report.violations.length > 0) {
console.error(`${report.violations.length} SDK boundary violations found`);
process.exit(1);
}