@ebowwa/claudecodehistory 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -2
- package/example/README.md +0 -79
- package/example/package.json +0 -37
- package/example/src/index.js +0 -275
- package/example/src/index.ts +0 -233
- package/example/tsconfig.json +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ebowwa/claudecodehistory",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "TypeScript library for accessing and analyzing Claude Code conversation history",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"dist/",
|
|
16
|
-
"example/",
|
|
17
16
|
"README",
|
|
18
17
|
"README.md",
|
|
19
18
|
"LICENSE"
|
package/example/README.md
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# Claude Code History MCP Server - Example
|
|
2
|
-
|
|
3
|
-
This is an example MCP server that demonstrates how to use the `@ebowwa/claudecodehistory` library to create an MCP server for Claude Code conversation history.
|
|
4
|
-
|
|
5
|
-
## About This Example
|
|
6
|
-
|
|
7
|
-
This example shows how to:
|
|
8
|
-
- Use the `ClaudeCodeHistoryService` class from the library
|
|
9
|
-
- Wrap it in an MCP server using the Model Context Protocol SDK
|
|
10
|
-
- Expose the service's functionality as MCP tools
|
|
11
|
-
|
|
12
|
-
## Features
|
|
13
|
-
|
|
14
|
-
This MCP server provides **4 powerful tools** for exploring your Claude Code conversation history:
|
|
15
|
-
|
|
16
|
-
### 1. `list_projects`
|
|
17
|
-
Discover all projects with Claude Code conversation history.
|
|
18
|
-
|
|
19
|
-
### 2. `list_sessions`
|
|
20
|
-
List conversation sessions for exploration and filtering.
|
|
21
|
-
|
|
22
|
-
### 3. `get_conversation_history`
|
|
23
|
-
Retrieve paginated conversation history with smart filtering.
|
|
24
|
-
|
|
25
|
-
### 4. `search_conversations`
|
|
26
|
-
Search across all conversation content by keywords.
|
|
27
|
-
|
|
28
|
-
## Quick Start
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
# From the example directory
|
|
32
|
-
cd example
|
|
33
|
-
|
|
34
|
-
# Install dependencies (uses bun)
|
|
35
|
-
bun install
|
|
36
|
-
|
|
37
|
-
# Run directly
|
|
38
|
-
bun src/index.ts
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Usage with MCP Clients
|
|
42
|
-
|
|
43
|
-
Add the following configuration to your MCP client (e.g., Claude Desktop):
|
|
44
|
-
|
|
45
|
-
```json
|
|
46
|
-
{
|
|
47
|
-
"mcpServers": {
|
|
48
|
-
"claude-code-history": {
|
|
49
|
-
"command": "bun",
|
|
50
|
-
"args": ["/path/to/claude-code-history-mcp/example/src/index.ts"]
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Development
|
|
57
|
-
|
|
58
|
-
- **Runtime:** `bun` (no build step required)
|
|
59
|
-
- **TypeScript:** Executed directly via bun
|
|
60
|
-
- **Hot reload:** `bun --hot src/index.ts`
|
|
61
|
-
|
|
62
|
-
## Library Dependency
|
|
63
|
-
|
|
64
|
-
This example imports from `@ebowwa/claudecodehistory` (the parent package):
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
import { ClaudeCodeHistoryService } from '@ebowwa/claudecodehistory';
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
The service provides all the core functionality for accessing Claude Code history:
|
|
71
|
-
|
|
72
|
-
- `getConversationHistory()` - Get paginated conversation history
|
|
73
|
-
- `searchConversations()` - Search by content
|
|
74
|
-
- `listProjects()` - List all projects
|
|
75
|
-
- `listSessions()` - List sessions with filters
|
|
76
|
-
|
|
77
|
-
## License
|
|
78
|
-
|
|
79
|
-
MIT
|
package/example/package.json
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@ebowwa/claude-code-history-example",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"private": true,
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "src/index.ts",
|
|
7
|
-
"bin": {
|
|
8
|
-
"claude-code-history-mcp": "src/index.ts"
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"dev": "bun --hot src/index.ts",
|
|
12
|
-
"start": "bun src/index.ts",
|
|
13
|
-
"typecheck": "tsc --noEmit"
|
|
14
|
-
},
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"@ebowwa/claudecodehistory": "file:..",
|
|
17
|
-
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
18
|
-
},
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"@types/node": "^24.0.4",
|
|
21
|
-
"typescript": "^5.8.3"
|
|
22
|
-
},
|
|
23
|
-
"keywords": [
|
|
24
|
-
"claude-code",
|
|
25
|
-
"mcp",
|
|
26
|
-
"history",
|
|
27
|
-
"conversation",
|
|
28
|
-
"example",
|
|
29
|
-
"typescript",
|
|
30
|
-
"bun"
|
|
31
|
-
],
|
|
32
|
-
"author": "ebowwa",
|
|
33
|
-
"license": "MIT",
|
|
34
|
-
"engines": {
|
|
35
|
-
"node": ">=18.0.0"
|
|
36
|
-
}
|
|
37
|
-
}
|
package/example/src/index.js
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
"use strict";
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
14
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
|
-
function step(op) {
|
|
17
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
20
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
|
-
switch (op[0]) {
|
|
22
|
-
case 0: case 1: t = op; break;
|
|
23
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
24
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
25
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
26
|
-
default:
|
|
27
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
28
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
29
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
30
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
31
|
-
if (t[2]) _.ops.pop();
|
|
32
|
-
_.trys.pop(); continue;
|
|
33
|
-
}
|
|
34
|
-
op = body.call(thisArg, _);
|
|
35
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
36
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
var index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
|
|
41
|
-
var stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
42
|
-
var types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
43
|
-
var claudecodehistory_1 = require("@ebowwa/claudecodehistory");
|
|
44
|
-
var server = new index_js_1.Server({
|
|
45
|
-
name: 'claude-code-history-mcp',
|
|
46
|
-
version: '1.1.0',
|
|
47
|
-
}, {
|
|
48
|
-
capabilities: {
|
|
49
|
-
tools: {},
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
var historyService = new claudecodehistory_1.ClaudeCodeHistoryService();
|
|
53
|
-
// Helper function to create response
|
|
54
|
-
var createResponse = function (data) { return ({
|
|
55
|
-
content: [{
|
|
56
|
-
type: 'text',
|
|
57
|
-
text: JSON.stringify(data),
|
|
58
|
-
}],
|
|
59
|
-
}); };
|
|
60
|
-
// Define available tools (ordered by recommended workflow)
|
|
61
|
-
var tools = [
|
|
62
|
-
{
|
|
63
|
-
name: 'list_projects',
|
|
64
|
-
description: 'List all projects with Claude Code conversation history (start here to explore available data)',
|
|
65
|
-
inputSchema: {
|
|
66
|
-
type: 'object',
|
|
67
|
-
properties: {},
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: 'list_sessions',
|
|
72
|
-
description: 'List conversation sessions for a project or date range (use after list_projects to find specific sessions)',
|
|
73
|
-
inputSchema: {
|
|
74
|
-
type: 'object',
|
|
75
|
-
properties: {
|
|
76
|
-
projectPath: {
|
|
77
|
-
type: 'string',
|
|
78
|
-
description: 'Filter by specific project path (optional)',
|
|
79
|
-
},
|
|
80
|
-
startDate: {
|
|
81
|
-
type: 'string',
|
|
82
|
-
description: 'Start date in ISO format (optional)',
|
|
83
|
-
},
|
|
84
|
-
endDate: {
|
|
85
|
-
type: 'string',
|
|
86
|
-
description: 'End date in ISO format (optional)',
|
|
87
|
-
},
|
|
88
|
-
timezone: {
|
|
89
|
-
type: 'string',
|
|
90
|
-
description: 'Timezone for date filtering (e.g., "Asia/Tokyo", "UTC"). Defaults to system timezone.',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
name: 'get_conversation_history',
|
|
97
|
-
description: 'Get paginated conversation history (use after exploring with list_projects/list_sessions for targeted data)',
|
|
98
|
-
inputSchema: {
|
|
99
|
-
type: 'object',
|
|
100
|
-
properties: {
|
|
101
|
-
sessionId: {
|
|
102
|
-
type: 'string',
|
|
103
|
-
description: 'Specific session ID to get history for (optional)',
|
|
104
|
-
},
|
|
105
|
-
startDate: {
|
|
106
|
-
type: 'string',
|
|
107
|
-
description: 'Start date in ISO format (optional)',
|
|
108
|
-
},
|
|
109
|
-
endDate: {
|
|
110
|
-
type: 'string',
|
|
111
|
-
description: 'End date in ISO format (optional)',
|
|
112
|
-
},
|
|
113
|
-
limit: {
|
|
114
|
-
type: 'number',
|
|
115
|
-
description: 'Maximum number of conversations to return (default: 20)',
|
|
116
|
-
default: 20,
|
|
117
|
-
},
|
|
118
|
-
offset: {
|
|
119
|
-
type: 'number',
|
|
120
|
-
description: 'Number of conversations to skip for pagination (default: 0)',
|
|
121
|
-
default: 0,
|
|
122
|
-
},
|
|
123
|
-
messageTypes: {
|
|
124
|
-
type: 'array',
|
|
125
|
-
items: {
|
|
126
|
-
type: 'string',
|
|
127
|
-
enum: ['user', 'assistant', 'system', 'result']
|
|
128
|
-
},
|
|
129
|
-
description: 'Filter by specific message types. Defaults to ["user"] to reduce data volume. Use ["user", "assistant"] to include Claude responses.',
|
|
130
|
-
default: ['user']
|
|
131
|
-
},
|
|
132
|
-
timezone: {
|
|
133
|
-
type: 'string',
|
|
134
|
-
description: 'Timezone for date filtering (e.g., "Asia/Tokyo", "UTC"). Defaults to system timezone.',
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
name: 'search_conversations',
|
|
141
|
-
description: 'Search through conversation history by content (useful for finding specific topics across all conversations)',
|
|
142
|
-
inputSchema: {
|
|
143
|
-
type: 'object',
|
|
144
|
-
properties: {
|
|
145
|
-
query: {
|
|
146
|
-
type: 'string',
|
|
147
|
-
description: 'Search query to find in conversation content',
|
|
148
|
-
},
|
|
149
|
-
limit: {
|
|
150
|
-
type: 'number',
|
|
151
|
-
description: 'Maximum number of results to return (default: 30)',
|
|
152
|
-
default: 30,
|
|
153
|
-
},
|
|
154
|
-
projectPath: {
|
|
155
|
-
type: 'string',
|
|
156
|
-
description: 'Filter by specific project path (optional)',
|
|
157
|
-
},
|
|
158
|
-
startDate: {
|
|
159
|
-
type: 'string',
|
|
160
|
-
description: 'Start date in ISO format (optional)',
|
|
161
|
-
},
|
|
162
|
-
endDate: {
|
|
163
|
-
type: 'string',
|
|
164
|
-
description: 'End date in ISO format (optional)',
|
|
165
|
-
},
|
|
166
|
-
timezone: {
|
|
167
|
-
type: 'string',
|
|
168
|
-
description: 'Timezone for date filtering (e.g., "Asia/Tokyo", "UTC"). Defaults to system timezone.',
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
required: ['query'],
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
];
|
|
175
|
-
// Handle list tools request
|
|
176
|
-
server.setRequestHandler(types_js_1.ListToolsRequestSchema, function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
177
|
-
return __generator(this, function (_a) {
|
|
178
|
-
return [2 /*return*/, { tools: tools }];
|
|
179
|
-
});
|
|
180
|
-
}); });
|
|
181
|
-
// Handle tool calls
|
|
182
|
-
server.setRequestHandler(types_js_1.CallToolRequestSchema, function (request) { return __awaiter(void 0, void 0, void 0, function () {
|
|
183
|
-
var _a, name, args, _b, history_1, query, results, projects, sessions, error_1, errorMessage;
|
|
184
|
-
return __generator(this, function (_c) {
|
|
185
|
-
switch (_c.label) {
|
|
186
|
-
case 0:
|
|
187
|
-
_a = request.params, name = _a.name, args = _a.arguments;
|
|
188
|
-
_c.label = 1;
|
|
189
|
-
case 1:
|
|
190
|
-
_c.trys.push([1, 12, , 13]);
|
|
191
|
-
_b = name;
|
|
192
|
-
switch (_b) {
|
|
193
|
-
case 'get_conversation_history': return [3 /*break*/, 2];
|
|
194
|
-
case 'search_conversations': return [3 /*break*/, 4];
|
|
195
|
-
case 'list_projects': return [3 /*break*/, 6];
|
|
196
|
-
case 'list_sessions': return [3 /*break*/, 8];
|
|
197
|
-
}
|
|
198
|
-
return [3 /*break*/, 10];
|
|
199
|
-
case 2: return [4 /*yield*/, historyService.getConversationHistory({
|
|
200
|
-
sessionId: args === null || args === void 0 ? void 0 : args.sessionId,
|
|
201
|
-
startDate: args === null || args === void 0 ? void 0 : args.startDate,
|
|
202
|
-
endDate: args === null || args === void 0 ? void 0 : args.endDate,
|
|
203
|
-
limit: (args === null || args === void 0 ? void 0 : args.limit) || 20,
|
|
204
|
-
offset: (args === null || args === void 0 ? void 0 : args.offset) || 0,
|
|
205
|
-
messageTypes: args === null || args === void 0 ? void 0 : args.messageTypes,
|
|
206
|
-
timezone: args === null || args === void 0 ? void 0 : args.timezone,
|
|
207
|
-
})];
|
|
208
|
-
case 3:
|
|
209
|
-
history_1 = _c.sent();
|
|
210
|
-
return [2 /*return*/, createResponse(history_1)];
|
|
211
|
-
case 4:
|
|
212
|
-
query = args === null || args === void 0 ? void 0 : args.query;
|
|
213
|
-
if (!query) {
|
|
214
|
-
throw new Error('Search query is required');
|
|
215
|
-
}
|
|
216
|
-
return [4 /*yield*/, historyService.searchConversations(query, {
|
|
217
|
-
limit: (args === null || args === void 0 ? void 0 : args.limit) || 30,
|
|
218
|
-
projectPath: args === null || args === void 0 ? void 0 : args.projectPath,
|
|
219
|
-
startDate: args === null || args === void 0 ? void 0 : args.startDate,
|
|
220
|
-
endDate: args === null || args === void 0 ? void 0 : args.endDate,
|
|
221
|
-
timezone: args === null || args === void 0 ? void 0 : args.timezone,
|
|
222
|
-
})];
|
|
223
|
-
case 5:
|
|
224
|
-
results = _c.sent();
|
|
225
|
-
return [2 /*return*/, createResponse(results)];
|
|
226
|
-
case 6: return [4 /*yield*/, historyService.listProjects()];
|
|
227
|
-
case 7:
|
|
228
|
-
projects = _c.sent();
|
|
229
|
-
return [2 /*return*/, createResponse(projects)];
|
|
230
|
-
case 8: return [4 /*yield*/, historyService.listSessions({
|
|
231
|
-
projectPath: args === null || args === void 0 ? void 0 : args.projectPath,
|
|
232
|
-
startDate: args === null || args === void 0 ? void 0 : args.startDate,
|
|
233
|
-
endDate: args === null || args === void 0 ? void 0 : args.endDate,
|
|
234
|
-
timezone: args === null || args === void 0 ? void 0 : args.timezone,
|
|
235
|
-
})];
|
|
236
|
-
case 9:
|
|
237
|
-
sessions = _c.sent();
|
|
238
|
-
return [2 /*return*/, createResponse(sessions)];
|
|
239
|
-
case 10: throw new Error("Unknown tool: ".concat(name));
|
|
240
|
-
case 11: return [3 /*break*/, 13];
|
|
241
|
-
case 12:
|
|
242
|
-
error_1 = _c.sent();
|
|
243
|
-
errorMessage = error_1 instanceof Error ? error_1.message : 'Unknown error';
|
|
244
|
-
return [2 /*return*/, {
|
|
245
|
-
content: [{
|
|
246
|
-
type: 'text',
|
|
247
|
-
text: "Error: ".concat(errorMessage),
|
|
248
|
-
}],
|
|
249
|
-
isError: true,
|
|
250
|
-
}];
|
|
251
|
-
case 13: return [2 /*return*/];
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}); });
|
|
255
|
-
// Start the server
|
|
256
|
-
function main() {
|
|
257
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
-
var transport;
|
|
259
|
-
return __generator(this, function (_a) {
|
|
260
|
-
switch (_a.label) {
|
|
261
|
-
case 0:
|
|
262
|
-
transport = new stdio_js_1.StdioServerTransport();
|
|
263
|
-
return [4 /*yield*/, server.connect(transport)];
|
|
264
|
-
case 1:
|
|
265
|
-
_a.sent();
|
|
266
|
-
console.error('Claude Code History MCP Server started');
|
|
267
|
-
return [2 /*return*/];
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
main().catch(function (error) {
|
|
273
|
-
console.error('Failed to start server:', error);
|
|
274
|
-
process.exit(1);
|
|
275
|
-
});
|
package/example/src/index.ts
DELETED
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
-
import {
|
|
6
|
-
CallToolRequestSchema,
|
|
7
|
-
ListToolsRequestSchema,
|
|
8
|
-
Tool
|
|
9
|
-
} from '@modelcontextprotocol/sdk/types.js';
|
|
10
|
-
import { ClaudeCodeHistoryService } from '@ebowwa/claudecodehistory';
|
|
11
|
-
|
|
12
|
-
const server = new Server(
|
|
13
|
-
{
|
|
14
|
-
name: 'claude-code-history-mcp',
|
|
15
|
-
version: '1.1.0',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
capabilities: {
|
|
19
|
-
tools: {},
|
|
20
|
-
},
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const historyService = new ClaudeCodeHistoryService();
|
|
25
|
-
|
|
26
|
-
// Helper function to create response
|
|
27
|
-
const createResponse = (data: any) => ({ // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
28
|
-
content: [{
|
|
29
|
-
type: 'text',
|
|
30
|
-
text: JSON.stringify(data),
|
|
31
|
-
}],
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Define available tools (ordered by recommended workflow)
|
|
35
|
-
const tools: Tool[] = [
|
|
36
|
-
{
|
|
37
|
-
name: 'list_projects',
|
|
38
|
-
description: 'List all projects with Claude Code conversation history (start here to explore available data)',
|
|
39
|
-
inputSchema: {
|
|
40
|
-
type: 'object',
|
|
41
|
-
properties: {},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
name: 'list_sessions',
|
|
46
|
-
description: 'List conversation sessions for a project or date range (use after list_projects to find specific sessions)',
|
|
47
|
-
inputSchema: {
|
|
48
|
-
type: 'object',
|
|
49
|
-
properties: {
|
|
50
|
-
projectPath: {
|
|
51
|
-
type: 'string',
|
|
52
|
-
description: 'Filter by specific project path (optional)',
|
|
53
|
-
},
|
|
54
|
-
startDate: {
|
|
55
|
-
type: 'string',
|
|
56
|
-
description: 'Start date in ISO format (optional)',
|
|
57
|
-
},
|
|
58
|
-
endDate: {
|
|
59
|
-
type: 'string',
|
|
60
|
-
description: 'End date in ISO format (optional)',
|
|
61
|
-
},
|
|
62
|
-
timezone: {
|
|
63
|
-
type: 'string',
|
|
64
|
-
description: 'Timezone for date filtering (e.g., "Asia/Tokyo", "UTC"). Defaults to system timezone.',
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
name: 'get_conversation_history',
|
|
71
|
-
description: 'Get paginated conversation history (use after exploring with list_projects/list_sessions for targeted data)',
|
|
72
|
-
inputSchema: {
|
|
73
|
-
type: 'object',
|
|
74
|
-
properties: {
|
|
75
|
-
sessionId: {
|
|
76
|
-
type: 'string',
|
|
77
|
-
description: 'Specific session ID to get history for (optional)',
|
|
78
|
-
},
|
|
79
|
-
startDate: {
|
|
80
|
-
type: 'string',
|
|
81
|
-
description: 'Start date in ISO format (optional)',
|
|
82
|
-
},
|
|
83
|
-
endDate: {
|
|
84
|
-
type: 'string',
|
|
85
|
-
description: 'End date in ISO format (optional)',
|
|
86
|
-
},
|
|
87
|
-
limit: {
|
|
88
|
-
type: 'number',
|
|
89
|
-
description: 'Maximum number of conversations to return (default: 20)',
|
|
90
|
-
default: 20,
|
|
91
|
-
},
|
|
92
|
-
offset: {
|
|
93
|
-
type: 'number',
|
|
94
|
-
description: 'Number of conversations to skip for pagination (default: 0)',
|
|
95
|
-
default: 0,
|
|
96
|
-
},
|
|
97
|
-
messageTypes: {
|
|
98
|
-
type: 'array',
|
|
99
|
-
items: {
|
|
100
|
-
type: 'string',
|
|
101
|
-
enum: ['user', 'assistant', 'system', 'result']
|
|
102
|
-
},
|
|
103
|
-
description: 'Filter by specific message types. Defaults to ["user"] to reduce data volume. Use ["user", "assistant"] to include Claude responses.',
|
|
104
|
-
default: ['user']
|
|
105
|
-
},
|
|
106
|
-
timezone: {
|
|
107
|
-
type: 'string',
|
|
108
|
-
description: 'Timezone for date filtering (e.g., "Asia/Tokyo", "UTC"). Defaults to system timezone.',
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: 'search_conversations',
|
|
115
|
-
description: 'Search through conversation history by content (useful for finding specific topics across all conversations)',
|
|
116
|
-
inputSchema: {
|
|
117
|
-
type: 'object',
|
|
118
|
-
properties: {
|
|
119
|
-
query: {
|
|
120
|
-
type: 'string',
|
|
121
|
-
description: 'Search query to find in conversation content',
|
|
122
|
-
},
|
|
123
|
-
limit: {
|
|
124
|
-
type: 'number',
|
|
125
|
-
description: 'Maximum number of results to return (default: 30)',
|
|
126
|
-
default: 30,
|
|
127
|
-
},
|
|
128
|
-
projectPath: {
|
|
129
|
-
type: 'string',
|
|
130
|
-
description: 'Filter by specific project path (optional)',
|
|
131
|
-
},
|
|
132
|
-
startDate: {
|
|
133
|
-
type: 'string',
|
|
134
|
-
description: 'Start date in ISO format (optional)',
|
|
135
|
-
},
|
|
136
|
-
endDate: {
|
|
137
|
-
type: 'string',
|
|
138
|
-
description: 'End date in ISO format (optional)',
|
|
139
|
-
},
|
|
140
|
-
timezone: {
|
|
141
|
-
type: 'string',
|
|
142
|
-
description: 'Timezone for date filtering (e.g., "Asia/Tokyo", "UTC"). Defaults to system timezone.',
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
required: ['query'],
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
];
|
|
149
|
-
|
|
150
|
-
// Handle list tools request
|
|
151
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
152
|
-
return { tools };
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// Handle tool calls
|
|
156
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
157
|
-
const { name, arguments: args } = request.params;
|
|
158
|
-
|
|
159
|
-
try {
|
|
160
|
-
switch (name) {
|
|
161
|
-
case 'get_conversation_history': {
|
|
162
|
-
const history = await historyService.getConversationHistory({
|
|
163
|
-
sessionId: args?.sessionId as string,
|
|
164
|
-
startDate: args?.startDate as string,
|
|
165
|
-
endDate: args?.endDate as string,
|
|
166
|
-
limit: (args?.limit as number) || 20,
|
|
167
|
-
offset: (args?.offset as number) || 0,
|
|
168
|
-
messageTypes: args?.messageTypes as ('user' | 'assistant' | 'system' | 'result')[],
|
|
169
|
-
timezone: args?.timezone as string,
|
|
170
|
-
});
|
|
171
|
-
return createResponse(history);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
case 'search_conversations': {
|
|
175
|
-
const query = args?.query as string;
|
|
176
|
-
if (!query) {
|
|
177
|
-
throw new Error('Search query is required');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const results = await historyService.searchConversations(
|
|
181
|
-
query,
|
|
182
|
-
{
|
|
183
|
-
limit: (args?.limit as number) || 30,
|
|
184
|
-
projectPath: args?.projectPath as string,
|
|
185
|
-
startDate: args?.startDate as string,
|
|
186
|
-
endDate: args?.endDate as string,
|
|
187
|
-
timezone: args?.timezone as string,
|
|
188
|
-
}
|
|
189
|
-
);
|
|
190
|
-
return createResponse(results);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
case 'list_projects': {
|
|
194
|
-
const projects = await historyService.listProjects();
|
|
195
|
-
return createResponse(projects);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
case 'list_sessions': {
|
|
199
|
-
const sessions = await historyService.listSessions({
|
|
200
|
-
projectPath: args?.projectPath as string,
|
|
201
|
-
startDate: args?.startDate as string,
|
|
202
|
-
endDate: args?.endDate as string,
|
|
203
|
-
timezone: args?.timezone as string,
|
|
204
|
-
});
|
|
205
|
-
return createResponse(sessions);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
default:
|
|
209
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
210
|
-
}
|
|
211
|
-
} catch (error) {
|
|
212
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
213
|
-
return {
|
|
214
|
-
content: [{
|
|
215
|
-
type: 'text',
|
|
216
|
-
text: `Error: ${errorMessage}`,
|
|
217
|
-
}],
|
|
218
|
-
isError: true,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
// Start the server
|
|
224
|
-
async function main() {
|
|
225
|
-
const transport = new StdioServerTransport();
|
|
226
|
-
await server.connect(transport);
|
|
227
|
-
console.error('Claude Code History MCP Server started');
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
main().catch((error) => {
|
|
231
|
-
console.error('Failed to start server:', error);
|
|
232
|
-
process.exit(1);
|
|
233
|
-
});
|
package/example/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"lib": ["ES2022"],
|
|
7
|
-
"strict": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
"resolveJsonModule": true,
|
|
12
|
-
"noEmit": true
|
|
13
|
-
},
|
|
14
|
-
"include": ["src/**/*"],
|
|
15
|
-
"exclude": ["node_modules", "dist"]
|
|
16
|
-
}
|