-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.cline
159 lines (127 loc) · 5.18 KB
/
.cline
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# TypeScript API MCP Server Architecture
## System Overview
The TypeScript API MCP Server is designed to provide AI agents with the ability to efficiently query and understand TypeScript APIs. It loads TypeDoc-generated JSON documentation and exposes it through a set of query endpoints following the Model Context Protocol (MCP).
## Components
### 1. TypeDoc Integration
- **Purpose**: Generate structured JSON documentation from TypeScript source code
- **Implementation**: Uses TypeDoc to extract type information, JSDoc comments, and relationships between symbols
- **Input**: TypeScript source files
- **Output**: JSON documentation with detailed API information
### 2. Data Indexing System
- **Purpose**: Efficiently index and organize TypeDoc JSON for fast querying
- **Implementation**: Creates multiple indexes (by ID, name, kind) for quick lookups
- **Key Features**:
- Symbol indexing by ID
- Symbol indexing by name
- Symbol categorization by kind (class, interface, function, etc.)
- Relationship tracking (inheritance, implementation)
### 3. MCP Server
- **Purpose**: Expose TypeScript API information through MCP tools and resources
- **Implementation**: Uses the MCP SDK to create a server with tools and resources
- **Components**:
- Server configuration
- Tool definitions
- Resource templates
- Request handlers
### 4. Query Handlers
- **Purpose**: Process queries and return relevant API information
- **Implementation**: Set of specialized handlers for different query types
- **Key Handlers**:
- Symbol search
- Member listing
- Type hierarchy resolution
- Implementation finding
- Usage discovery
## Data Flow
1. **Documentation Generation**:
- TypeScript source code → TypeDoc → JSON documentation
2. **Server Initialization**:
- Load JSON documentation
- Build indexes
- Register MCP tools and resources
3. **Query Processing**:
- Receive query from agent
- Route to appropriate handler
- Execute query against indexes
- Format and return results
## File Structure
```
typescript-api-mcp/
├── src/
│ ├── sample-api/ # Sample TypeScript API for testing
│ │ ├── types.ts # Type definitions
│ │ ├── task-manager.ts # Classes and implementations
│ │ ├── utils.ts # Utility functions
│ │ └── index.ts # API exports
│ │
│ └── mcp-server/ # MCP server implementation
│ ├── types.ts # Type definitions for the server
│ ├── utils.ts # Utility functions
│ ├── handlers.ts # Query handlers
│ ├── schemas.ts # JSON schemas for tools
│ ├── server.ts # Server implementation
│ └── index.ts # Entry point
│
├── tests/ # Test files
│ └── handlers.test.ts # Tests for API parsing
│
├── docs/ # Generated documentation
│ └── api.json # TypeDoc JSON output
│
├── dist/ # Compiled JavaScript
├── package.json # Project configuration
└── tsconfig.json # TypeScript configuration
```
## Key Interfaces
### TypeDoc JSON Structure
The system works with TypeDoc JSON, which follows this general structure:
```typescript
interface TypeDocJson {
id: number;
name: string;
kind: number;
kindString: string;
children?: TypeDocSymbol[];
}
interface TypeDocSymbol {
id: number;
name: string;
kind: number;
kindString?: string;
comment?: { summary?: Array<{ kind: string; text: string }> };
children?: TypeDocSymbol[];
signatures?: TypeDocSignature[];
type?: TypeDocType;
// ... other properties
}
```
### MCP Tools
The server exposes these main tools:
1. `search_symbols`: Find symbols by name/pattern
2. `get_symbol_details`: Get detailed information about a symbol
3. `list_members`: List class/interface members
4. `get_parameter_info`: Get function parameter details
5. `find_implementations`: Find implementations of interfaces
6. `search_by_return_type`: Find functions by return type
7. `search_by_description`: Search in JSDoc comments
8. `get_type_hierarchy`: Get inheritance relationships
9. `find_usages`: Find symbol usages
## Design Decisions
1. **Separation of Concerns**:
- Split functionality into multiple files for better maintainability
- Clear separation between TypeDoc parsing, indexing, and query handling
2. **Efficient Indexing**:
- Multiple indexes for fast lookups
- In-memory storage for quick access
3. **Comprehensive Query Capabilities**:
- Wide range of tools to cover different query needs
- Support for both direct lookups and relationship exploration
4. **Extensibility**:
- Modular design allows for adding new query capabilities
- Clear interfaces for extending functionality
## Future Enhancements
1. **Persistent Storage**: Option to cache indexed data for faster startup
2. **Advanced Search**: Fuzzy matching and semantic search capabilities
3. **Code Generation**: Generate example code for API usage
4. **Visualization**: Generate visual representations of type hierarchies
5. **Cross-Reference Analysis**: More advanced relationship tracking