Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/diagram/create.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ColorPreset, EdgeStyle, ShapeType } from '@/tools/schemas';
import type { ColorPreset, EdgeStyle, ShapeType } from '../tools/schemas.js';
import {
colorPresets,
createBaseElement,
estimateTextHeight,
estimateTextWidth,
generateId,
} from './primitives';
import { ElementType, type ExcalidrawElement } from './types';
} from './primitives.js';
import { ElementType, type ExcalidrawElement } from './types.js';

export type CreateNodeOptions = {
label: string;
Expand Down
2 changes: 1 addition & 1 deletion src/diagram/delete.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ExcalidrawElement } from './types';
import type { ExcalidrawElement } from './types.js';

export function deleteElementById(
elements: ExcalidrawElement[],
Expand Down
2 changes: 1 addition & 1 deletion src/diagram/format.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Diagram, Node } from './types';
import type { Diagram, Node } from './types.js';

enum ItemType {
Edge = 'edge',
Expand Down
6 changes: 3 additions & 3 deletions src/diagram/parse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { shapeEnum } from '@/tools/schemas';
import { emojiForColorAndShape } from '@/utils/emoji';
import { ElementType, type Diagram, type NodeShape } from './types';
import { shapeEnum } from '../tools/schemas.js';
import { emojiForColorAndShape } from '../utils/emoji.js';
import { ElementType, type Diagram, type NodeShape } from './types.js';

const nodeTypes: Set<string> = new Set([
...shapeEnum.options,
Expand Down
2 changes: 1 addition & 1 deletion src/diagram/primitives.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ColorPreset } from '@/tools/schemas';
import type { ColorPreset } from '../tools/schemas.js';

type ColorConfig = {
backgroundColor: string;
Expand Down
4 changes: 2 additions & 2 deletions src/diagram/query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { shapeEnum } from '@/tools/schemas';
import type { ExcalidrawElement } from './types';
import { shapeEnum } from '../tools/schemas.js';
import type { ExcalidrawElement } from './types.js';

export const findNodeById = (
elements: ExcalidrawElement[],
Expand Down
6 changes: 3 additions & 3 deletions src/diagram/tests/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest';
import { Assert } from '@/utils/assert';
import { createEdgeElements, createNodeElements } from '../create';
import type { ExcalidrawElement } from '../types';
import { Assert } from '../../utils/assert.js';
import { createEdgeElements, createNodeElements } from '../create.js';
import type { ExcalidrawElement } from '../types.js';

function makeNode(
id: string,
Expand Down
4 changes: 2 additions & 2 deletions src/diagram/tests/format.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import { formatDiagramMarkdown } from '../format';
import type { Diagram, Node } from '../types';
import { formatDiagramMarkdown } from '../format.js';
import type { Diagram, Node } from '../types.js';

function makeNode(id: string, label: string | null = null): Node {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/diagram/tests/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
calculateNextPosition,
resolveNode,
resolveNodeByRole,
} from '../query';
import type { ExcalidrawElement } from '../types';
} from '../query.js';
import type { ExcalidrawElement } from '../types.js';

function makeNode(
id: string,
Expand Down
2 changes: 1 addition & 1 deletion src/diagram/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ShapeType } from '@/tools/schemas';
import type { ShapeType } from '../tools/schemas.js';

export enum ElementType {
Arrow = 'arrow',
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

import { registerAllTools } from './tools/index';
import { registerAllTools } from './tools/index.js';

const argv = yargs(hideBin(process.argv))
.option('diagram', {
Expand Down
10 changes: 5 additions & 5 deletions src/tools/handlers/createEdge.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createEdgeElements } from '@/diagram/create';
import { resolveNodeByRole } from '@/diagram/query';
import type { ExcalidrawFile } from '@/diagram/types';
import type { EdgeStyle } from '@/tools/schemas';
import type { WriteHandlerResult } from './types';
import { createEdgeElements } from '../../diagram/create.js';
import { resolveNodeByRole } from '../../diagram/query.js';
import type { ExcalidrawFile } from '../../diagram/types.js';
import type { EdgeStyle } from '../schemas.js';
import type { WriteHandlerResult } from './types.js';

interface CreateEdgeArgs {
from: string;
Expand Down
10 changes: 5 additions & 5 deletions src/tools/handlers/createNode.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type CreateNodeOptions, createNodeElements } from '@/diagram/create';
import { calculateNextPosition } from '@/diagram/query';
import type { ExcalidrawFile } from '@/diagram/types';
import type { WriteHandlerResult } from './types';
import type { ColorPreset, ShapeType } from '@/tools/schemas';
import { type CreateNodeOptions, createNodeElements } from '../../diagram/create.js';
import { calculateNextPosition } from '../../diagram/query.js';
import type { ExcalidrawFile } from '../../diagram/types.js';
import type { WriteHandlerResult } from './types.js';
import type { ColorPreset, ShapeType } from '../schemas.js';

interface CreateNodeArgs {
label: string;
Expand Down
8 changes: 4 additions & 4 deletions src/tools/handlers/deleteElement.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deleteElementById } from '@/diagram/delete';
import { resolveNode } from '@/diagram/query';
import type { ExcalidrawFile } from '@/diagram/types';
import type { WriteHandlerResult } from './types';
import { deleteElementById } from '../../diagram/delete.js';
import { resolveNode } from '../../diagram/query.js';
import type { ExcalidrawFile } from '../../diagram/types.js';
import type { WriteHandlerResult } from './types.js';

interface DeleteElementArgs {
id: string;
Expand Down
8 changes: 4 additions & 4 deletions src/tools/handlers/getFullDiagramState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { formatDiagramMarkdown } from '@/diagram/format';
import { parseDiagram } from '@/diagram/parse';
import type { ExcalidrawFile } from '@/diagram/types';
import type { ReadHandlerResult } from './types';
import { formatDiagramMarkdown } from '../../diagram/format.js';
import { parseDiagram } from '../../diagram/parse.js';
import type { ExcalidrawFile } from '../../diagram/types.js';
import type { ReadHandlerResult } from './types.js';

export function getFullDiagramState(file: ExcalidrawFile): ReadHandlerResult {
const diagram = parseDiagram(file);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/handlers/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ExcalidrawFile } from '@/diagram/types';
import type { ExcalidrawFile } from '../../diagram/types.js';

export type ReadHandlerResult =
| { ok: true; message: string }
Expand Down
12 changes: 6 additions & 6 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';

import { createEdge } from './handlers/createEdge';
import { createNode } from './handlers/createNode';
import { deleteElement } from './handlers/deleteElement';
import { getFullDiagramState } from './handlers/getFullDiagramState';
import { withDiagramRead, withDiagramWrite } from './middleware';
import { colorEnum, edgeStyleEnum, shapeEnum } from './schemas';
import { createEdge } from './handlers/createEdge.js';
import { createNode } from './handlers/createNode.js';
import { deleteElement } from './handlers/deleteElement.js';
import { getFullDiagramState } from './handlers/getFullDiagramState.js';
import { withDiagramRead, withDiagramWrite } from './middleware.js';
import { colorEnum, edgeStyleEnum, shapeEnum } from './schemas.js';

export function registerAllTools(server: McpServer, diagramPath: string) {
server.registerTool(
Expand Down
4 changes: 2 additions & 2 deletions src/tools/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fs from 'node:fs/promises';

import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';

import type { ExcalidrawFile } from '@/diagram/types';
import type { ReadHandlerResult, WriteHandlerResult } from './handlers/types';
import type { ExcalidrawFile } from '../diagram/types.js';
import type { ReadHandlerResult, WriteHandlerResult } from './handlers/types.js';

async function loadDiagram(path: string): Promise<ExcalidrawFile> {
const content = await fs.readFile(path, 'utf8');
Expand Down
2 changes: 1 addition & 1 deletion src/utils/emoji.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ShapeType } from '@/tools/schemas';
import type { ShapeType } from '../tools/schemas.js';

type ColorFamily = 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'purple';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/tests/emoji.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { emojiForColorAndShape } from '../emoji';
import { emojiForColorAndShape } from '../emoji.js';

describe('emojiForColorAndShape', () => {
it('returns correct emoji for each color family', () => {
Expand Down
10 changes: 3 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"outDir": "dist",
"rootDir": "src",
"types": ["node"],
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
"types": ["node"]
},
"include": ["src/**/*.ts"]
}