@k-system/tickr-mcp 0.8.5 → 0.9.0

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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Zkontroluje zda je debug logování zapnuté (TICKR_DEBUG=true|1).
3
+ */
4
+ export declare function isDebugEnabled(): boolean;
5
+ /**
6
+ * Zaloguje MCP tool call do ~/.tickr/mcp-debug.log.
7
+ * Pokud debug není zapnutý, funkce je no-op.
8
+ * Pokud zápis selže, tiše ignoruje — debug log nesmí způsobit crash.
9
+ */
10
+ export declare function debugLog(toolName: string, params: Record<string, unknown>, responseStatus: "ok" | "error", durationMs: number): void;
11
+ //# sourceMappingURL=debug-logger.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { appendFileSync, statSync, renameSync, mkdirSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { homedir } from "node:os";
4
+ const MAX_LOG_SIZE = 10 * 1024 * 1024; // 10 MB
5
+ const MAX_PARAMS_LENGTH = 200;
6
+ let _debugEnabled = null;
7
+ /**
8
+ * Zkontroluje zda je debug logování zapnuté (TICKR_DEBUG=true|1).
9
+ */
10
+ export function isDebugEnabled() {
11
+ if (_debugEnabled === null) {
12
+ const val = process.env.TICKR_DEBUG;
13
+ _debugEnabled = val === "true" || val === "1";
14
+ }
15
+ return _debugEnabled;
16
+ }
17
+ /**
18
+ * Zaloguje MCP tool call do ~/.tickr/mcp-debug.log.
19
+ * Pokud debug není zapnutý, funkce je no-op.
20
+ * Pokud zápis selže, tiše ignoruje — debug log nesmí způsobit crash.
21
+ */
22
+ export function debugLog(toolName, params, responseStatus, durationMs) {
23
+ if (!isDebugEnabled())
24
+ return;
25
+ try {
26
+ const dir = join(homedir(), ".tickr");
27
+ mkdirSync(dir, { recursive: true });
28
+ const logPath = join(dir, "mcp-debug.log");
29
+ // Rotace — pokud soubor > 10 MB, přejmenuj na .log.old
30
+ try {
31
+ const stats = statSync(logPath);
32
+ if (stats.size > MAX_LOG_SIZE) {
33
+ renameSync(logPath, logPath + ".old");
34
+ }
35
+ }
36
+ catch {
37
+ // Soubor ještě neexistuje — ok
38
+ }
39
+ // Zkrátit params na max 200 znaků
40
+ let paramsStr = JSON.stringify(params);
41
+ if (paramsStr.length > MAX_PARAMS_LENGTH) {
42
+ paramsStr = paramsStr.slice(0, MAX_PARAMS_LENGTH - 3) + "...";
43
+ }
44
+ const timestamp = new Date().toISOString();
45
+ const line = `[${timestamp}] [${toolName}] params=${paramsStr} → ${responseStatus} (${durationMs}ms)\n`;
46
+ appendFileSync(logPath, line, "utf-8");
47
+ }
48
+ catch {
49
+ // Tiše ignoruj — debug log nesmí způsobit crash
50
+ }
51
+ }
52
+ //# sourceMappingURL=debug-logger.js.map
package/dist/server.js CHANGED
@@ -2,6 +2,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
3
  import { loadConfig } from "./config.js";
4
4
  import { ApiClient } from "./api-client.js";
5
+ import { debugLog, isDebugEnabled } from "./debug-logger.js";
5
6
  // Tools
6
7
  import { registerCreateTicket } from "./tools/create-ticket.js";
7
8
  import { registerListTickets } from "./tools/list-tickets.js";
@@ -95,6 +96,30 @@ export async function startServer() {
95
96
  name: "tickr",
96
97
  version: "0.1.5",
97
98
  });
99
+ // Debug logging — obalení server.tool pro automatické logování všech tool callů
100
+ if (isDebugEnabled()) {
101
+ const originalTool = server.tool.bind(server);
102
+ const wrappedTool = function (...args) {
103
+ // server.tool má více overloadů — handler je vždy poslední argument
104
+ const handlerIndex = args.length - 1;
105
+ const name = args[0];
106
+ const originalHandler = args[handlerIndex];
107
+ args[handlerIndex] = async (params, extra) => {
108
+ const start = Date.now();
109
+ try {
110
+ const result = await originalHandler(params, extra);
111
+ debugLog(name, (params ?? {}), result.isError ? "error" : "ok", Date.now() - start);
112
+ return result;
113
+ }
114
+ catch (err) {
115
+ debugLog(name, (params ?? {}), "error", Date.now() - start);
116
+ throw err;
117
+ }
118
+ };
119
+ return originalTool.apply(server, args);
120
+ };
121
+ server.tool = wrappedTool;
122
+ }
98
123
  // Registrace tools
99
124
  registerCreateTicket(server, api);
100
125
  registerListTickets(server, api);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k-system/tickr-mcp",
3
- "version": "0.8.5",
3
+ "version": "0.9.0",
4
4
  "description": "MCP server for Tickr project management — 56 tools + setup CLI wizard",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",