Skip to content

Commit 72a5e75

Browse files
committed
fix: add metrics tracking for POST tools
POST tools (place_order, modify_order, cancel_order, place_gtt_order, delete_gtt_order, modify_gtt_order) were missing trackToolCall() calls, causing them to not appear in metrics output. Added trackToolCall() to all POST tool handlers. Also added *.local* to gitignore and fixed formatting.
1 parent cb81e01 commit 72a5e75

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ test-binary
8181
kite-mcp-server-*
8282

8383
.memory
84+
85+
# Local files
86+
*.local*

app/metrics/daily_metrics_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestParseDailyMetric(t *testing.T) {
122122
}{
123123
{"tool_calls_quotes_2025-08-05", "tool_calls_quotes", "2025-08-05"},
124124
{"tool_errors_login_session_error_2025-12-31", "tool_errors_login_session_error", "2025-12-31"},
125-
{"legacy_counter", "", ""}, // Not a daily metric
125+
{"legacy_counter", "", ""}, // Not a daily metric
126126
{"tool_calls_quotes_20250805", "", ""}, // Wrong date format
127127
}
128128

@@ -135,4 +135,4 @@ func TestParseDailyMetric(t *testing.T) {
135135
}
136136
})
137137
}
138-
}
138+
}

app/metrics/metrics.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,25 +213,25 @@ func (m *Manager) isDailyMetric(key string) bool {
213213
if len(parts) < 2 {
214214
return false
215215
}
216-
216+
217217
// Check if we have a non-empty base name
218218
baseName := strings.Join(parts[:len(parts)-1], "_")
219219
if baseName == "" {
220220
return false
221221
}
222-
222+
223223
// Check if the last part looks like a date (YYYY-MM-DD)
224224
lastPart := parts[len(parts)-1]
225225
if len(lastPart) != 10 || strings.Count(lastPart, "-") != 2 {
226226
return false
227227
}
228-
228+
229229
// Basic validation that it looks like YYYY-MM-DD
230230
dateParts := strings.Split(lastPart, "-")
231231
if len(dateParts) != 3 || len(dateParts[0]) != 4 || len(dateParts[1]) != 2 || len(dateParts[2]) != 2 {
232232
return false
233233
}
234-
234+
235235
return true
236236
}
237237

@@ -240,7 +240,7 @@ func (m *Manager) parseDailyMetric(key string) (baseName, date string) {
240240
if !m.isDailyMetric(key) {
241241
return "", ""
242242
}
243-
243+
244244
parts := strings.Split(key, "_")
245245
date = parts[len(parts)-1]
246246
baseName = strings.Join(parts[:len(parts)-1], "_")
@@ -275,7 +275,7 @@ func (m *Manager) WritePrometheus(buf *bytes.Buffer) {
275275
return true
276276
}
277277
value := atomic.LoadInt64(val.(*int64))
278-
278+
279279
// Check if this is a daily metric (has date suffix)
280280
if m.isDailyMetric(name) {
281281
baseName, date := m.parseDailyMetric(name)

mcp/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func PaginatedToolHandler[T any](manager *kc.Manager, toolName string, apiCall f
344344

345345
return handler.MarshalResponse(responseData, toolName)
346346
})
347-
347+
348348
if err != nil {
349349
handler.trackToolError(toolName, "execution_error")
350350
} else if result != nil && result.IsError {

mcp/post_tools.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (*PlaceOrderTool) Tool() mcp.Tool {
8383
func (*PlaceOrderTool) Handler(manager *kc.Manager) server.ToolHandlerFunc {
8484
handler := NewToolHandler(manager)
8585
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
86+
handler.trackToolCall("place_order")
8687
args := request.GetArguments()
8788

8889
// Validate required parameters
@@ -164,6 +165,7 @@ func (*ModifyOrderTool) Tool() mcp.Tool {
164165
func (*ModifyOrderTool) Handler(manager *kc.Manager) server.ToolHandlerFunc {
165166
handler := NewToolHandler(manager)
166167
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
168+
handler.trackToolCall("modify_order")
167169
args := request.GetArguments()
168170

169171
// Validate required parameters
@@ -216,6 +218,7 @@ func (*CancelOrderTool) Tool() mcp.Tool {
216218
func (*CancelOrderTool) Handler(manager *kc.Manager) server.ToolHandlerFunc {
217219
handler := NewToolHandler(manager)
218220
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
221+
handler.trackToolCall("cancel_order")
219222
args := request.GetArguments()
220223

221224
// Validate required parameters
@@ -307,6 +310,7 @@ func (*PlaceGTTOrderTool) Tool() mcp.Tool {
307310
func (*PlaceGTTOrderTool) Handler(manager *kc.Manager) server.ToolHandlerFunc {
308311
handler := NewToolHandler(manager)
309312
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
313+
handler.trackToolCall("place_gtt_order")
310314
args := request.GetArguments()
311315

312316
// Validate required parameters
@@ -379,6 +383,7 @@ func (*DeleteGTTOrderTool) Tool() mcp.Tool {
379383
func (*DeleteGTTOrderTool) Handler(manager *kc.Manager) server.ToolHandlerFunc {
380384
handler := NewToolHandler(manager)
381385
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
386+
handler.trackToolCall("delete_gtt_order")
382387
args := request.GetArguments()
383388

384389
// Validate required parameters
@@ -469,6 +474,7 @@ func (*ModifyGTTOrderTool) Tool() mcp.Tool {
469474
func (*ModifyGTTOrderTool) Handler(manager *kc.Manager) server.ToolHandlerFunc {
470475
handler := NewToolHandler(manager)
471476
return func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
477+
handler.trackToolCall("modify_gtt_order")
472478
args := request.GetArguments()
473479

474480
// Validate required parameters

0 commit comments

Comments
 (0)