Skip to content

Commit d481f36

Browse files
committed
Add manual tool classification and description overrides
1 parent b850408 commit d481f36

29 files changed

Lines changed: 1907 additions & 67 deletions

‎frontend/src/services/api.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,22 @@ class APIService {
399399
return this.request<GlobalToolsResponse>('/api/v1/tools')
400400
}
401401

402+
// Override tool annotations and/or description
403+
async overrideTools(payload: { server_name: string; tools: string[]; description?: string; annotations?: any }): Promise<APIResponse<{ success: boolean; message: string }>> {
404+
return this.request<{ success: boolean; message: string }>('/api/v1/tools/override', {
405+
method: 'POST',
406+
body: JSON.stringify(payload),
407+
})
408+
}
409+
410+
// Reset tool overrides to upstream defaults
411+
async resetToolOverrides(payload: { server_name: string; tools: string[] }): Promise<APIResponse<{ success: boolean; message: string }>> {
412+
return this.request<{ success: boolean; message: string }>('/api/v1/tools/reset-override', {
413+
method: 'POST',
414+
body: JSON.stringify(payload),
415+
})
416+
}
417+
402418
// Tool-level quarantine (Spec 032) + scan-gate hold evidence (Spec 088).
403419
//
404420
// The record source stays `/tools/export`: those approval records are durable,

‎frontend/src/types/api.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ export interface GlobalTool {
344344
held_reason?: string // "scan_findings" (threat) | "scan_coverage" (precaution)
345345
held_verdict?: string // "dangerous" | "warnings" | "clean"
346346
held_signals?: string[] // matched deterministic check ids, producer order, ≤16
347+
is_custom_override?: boolean
348+
original_description?: string
347349
// derived locally: enabled = !disabled && !config_denied
348350
}
349351

@@ -361,6 +363,19 @@ export interface GlobalToolsResponse {
361363
failed_servers: string[]
362364
}
363365

366+
// Tool Override requests
367+
export interface OverrideToolsRequest {
368+
server_name: string
369+
tools: string[]
370+
description?: string
371+
annotations?: ToolAnnotation
372+
}
373+
374+
export interface ResetToolOverridesRequest {
375+
server_name: string
376+
tools: string[]
377+
}
378+
364379
// Tool Annotation types
365380
export interface ToolAnnotation {
366381
title?: string
@@ -406,6 +421,8 @@ export interface Tool {
406421
approval_status?: string
407422
disabled?: boolean
408423
config_denied?: boolean
424+
is_custom_override?: boolean
425+
original_description?: string
409426
}
410427

411428
// Tool approval types (Spec 032)

‎frontend/src/views/Tools.vue‎

Lines changed: 647 additions & 13 deletions
Large diffs are not rendered by default.
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
import { describe, it, expect, beforeEach, vi } from 'vitest'
2+
import { mount, flushPromises } from '@vue/test-utils'
3+
import { createPinia, setActivePinia } from 'pinia'
4+
import Tools from '@/views/Tools.vue'
5+
import api from '@/services/api'
6+
7+
vi.mock('@/services/api', () => ({
8+
default: {
9+
getGlobalTools: vi.fn(),
10+
setToolEnabled: vi.fn(),
11+
approveTools: vi.fn(),
12+
blockTools: vi.fn(),
13+
overrideTools: vi.fn(),
14+
resetToolOverrides: vi.fn(),
15+
},
16+
}))
17+
18+
const globalStubs = { CollapsibleHintsPanel: { template: '<div />' } }
19+
20+
const TOOLS = [
21+
{
22+
name: 'get_issue',
23+
server_name: 'jira',
24+
approval_status: 'approved',
25+
enabled: true,
26+
description: 'Get issue details',
27+
annotations: { readOnlyHint: true },
28+
is_custom_override: false,
29+
},
30+
{
31+
name: 'delete_issue',
32+
server_name: 'jira',
33+
approval_status: 'approved',
34+
enabled: true,
35+
description: 'Delete issue',
36+
annotations: { destructiveHint: true },
37+
is_custom_override: true,
38+
original_description: 'Original delete description',
39+
},
40+
{
41+
name: 'list_repos',
42+
server_name: 'github',
43+
approval_status: 'approved',
44+
enabled: true,
45+
description: 'List user repos',
46+
annotations: { readOnlyHint: true },
47+
is_custom_override: false,
48+
},
49+
]
50+
51+
function mountView() {
52+
return mount(Tools, { global: { plugins: [createPinia()], stubs: globalStubs } })
53+
}
54+
55+
describe('Tools — pattern selection and tool overrides', () => {
56+
beforeEach(() => {
57+
setActivePinia(createPinia())
58+
;(api.getGlobalTools as any).mockResolvedValue({
59+
success: true,
60+
data: {
61+
stats: { total: 3, enabled: 3, disabled: 0, pending_approval: 0 },
62+
tools: TOOLS,
63+
},
64+
})
65+
;(api.overrideTools as any).mockResolvedValue({ success: true })
66+
;(api.resetToolOverrides as any).mockResolvedValue({ success: true })
67+
})
68+
69+
it('selects tools by pattern matching wildcards', async () => {
70+
const wrapper = mountView()
71+
await flushPromises()
72+
73+
const patternInput = wrapper.find('[data-test="pattern-select-input"]')
74+
expect(patternInput.exists()).toBe(true)
75+
76+
// Select tools matching "*issue*"
77+
await patternInput.setValue('*issue*')
78+
await wrapper.find('[data-test="pattern-select-btn"]').trigger('click')
79+
await flushPromises()
80+
81+
// Batch bar should show 2 tools selected
82+
const batchBar = wrapper.find('[data-test="tools-batch-bar"]')
83+
expect(batchBar.exists()).toBe(true)
84+
expect(batchBar.text()).toContain('2 tools selected')
85+
86+
// Deselect tools matching "get_*"
87+
await patternInput.setValue('get_*')
88+
await wrapper.find('[data-test="pattern-deselect-btn"]').trigger('click')
89+
await flushPromises()
90+
91+
// Batch bar should show 1 tool selected (delete_issue)
92+
expect(wrapper.find('[data-test="tools-batch-bar"]').text()).toContain('1 tool selected')
93+
})
94+
95+
it('renders custom badge on overridden tools in the table', async () => {
96+
const wrapper = mountView()
97+
await flushPromises()
98+
99+
const text = wrapper.text()
100+
expect(text).toContain('custom')
101+
})
102+
103+
it('performs batch override and resets overrides', async () => {
104+
const wrapper = mountView()
105+
await flushPromises()
106+
107+
// Select all
108+
await wrapper.find('[data-test="tools-select-all"]').setValue(true)
109+
await flushPromises()
110+
111+
// Open batch override modal
112+
const batchOverrideBtn = wrapper.find('[data-test="batch-override"]')
113+
expect(batchOverrideBtn.exists()).toBe(true)
114+
await batchOverrideBtn.trigger('click')
115+
await flushPromises()
116+
117+
const modal = wrapper.find('[data-test="batch-override-modal"]')
118+
expect(modal.exists()).toBe(true)
119+
120+
// Click Read-Only preset
121+
await wrapper.find('[data-test="batch-preset-read"]').trigger('click')
122+
await flushPromises()
123+
124+
// Apply overrides
125+
await wrapper.find('[data-test="batch-override-save"]').trigger('click')
126+
await flushPromises()
127+
128+
expect(api.overrideTools).toHaveBeenCalled()
129+
130+
// Test batch reset
131+
await wrapper.find('[data-test="tools-select-all"]').setValue(true)
132+
await flushPromises()
133+
await wrapper.find('[data-test="batch-reset-override"]').trigger('click')
134+
await flushPromises()
135+
136+
expect(api.resetToolOverrides).toHaveBeenCalled()
137+
})
138+
139+
it('allows editing overrides in detail modal and resetting to upstream', async () => {
140+
const wrapper = mountView()
141+
await flushPromises()
142+
143+
// Find the row for delete_issue (which has is_custom_override: true)
144+
const rows = wrapper.findAll('[data-test="tool-row"]')
145+
expect(rows.length).toBe(3)
146+
const deleteRow = rows.find(r => r.text().includes('delete_issue'))
147+
expect(deleteRow).toBeDefined()
148+
await deleteRow!.trigger('click')
149+
await flushPromises()
150+
151+
const detailModal = wrapper.find('[data-test="tool-detail-modal"]')
152+
expect(detailModal.exists()).toBe(true)
153+
154+
// Reset button should exist for overridden tool
155+
const resetBtn = wrapper.find('[data-test="detail-reset-btn"]')
156+
expect(resetBtn.exists()).toBe(true)
157+
158+
// Enter edit mode
159+
const editBtn = wrapper.find('[data-test="detail-edit-btn"]')
160+
expect(editBtn.exists()).toBe(true)
161+
await editBtn.trigger('click')
162+
await flushPromises()
163+
164+
const descInput = wrapper.find('[data-test="detail-desc-input"]')
165+
expect(descInput.exists()).toBe(true)
166+
await descInput.setValue('Custom new description')
167+
168+
const saveBtn = wrapper.find('[data-test="detail-save-btn"]')
169+
await saveBtn.trigger('click')
170+
await flushPromises()
171+
172+
expect(api.overrideTools).toHaveBeenCalledWith(
173+
expect.objectContaining({
174+
server_name: 'jira',
175+
tools: ['delete_issue'],
176+
description: 'Custom new description',
177+
})
178+
)
179+
})
180+
})

‎internal/config/config.go‎

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,9 @@ type ServerConfig struct {
749749
EnabledTools []string `json:"enabled_tools,omitempty" mapstructure:"enabled_tools"` // Allowlist: only these tools are exposed; mutually exclusive with disabled_tools
750750
DisabledTools []string `json:"disabled_tools,omitempty" mapstructure:"disabled_tools"` // Denylist: these tools are hidden; mutually exclusive with enabled_tools
751751

752+
// ToolOverrides maps explicit tool names to manual overrides (description and/or annotations).
753+
ToolOverrides map[string]*ToolOverride `json:"tool_overrides,omitempty" mapstructure:"tool-overrides"`
754+
752755
// SourceRegistryID records which registry this server was added from (empty
753756
// for manually-configured servers). MCP-866: surfaced in the approval /
754757
// quarantine view so a reviewer can see a server's origin.
@@ -1382,15 +1385,16 @@ func ConvertFromCursorFormat(cursorConfig *CursorMCPConfig) []*ServerConfig {
13821385

13831386
// ToolMetadata represents tool information stored in the index
13841387
type ToolMetadata struct {
1385-
Name string `json:"name"`
1386-
ServerName string `json:"server_name"`
1387-
Description string `json:"description"`
1388-
ParamsJSON string `json:"params_json"`
1389-
OutputSchemaJSON string `json:"output_schema_json,omitempty"` // declared output schema, raw JSON bytes (Spec 056)
1390-
Hash string `json:"hash"`
1391-
Created time.Time `json:"created"`
1392-
Updated time.Time `json:"updated"`
1393-
Annotations *ToolAnnotations `json:"annotations,omitempty"`
1388+
Name string `json:"name"`
1389+
ServerName string `json:"server_name"`
1390+
Description string `json:"description"`
1391+
OriginalDescription string `json:"original_description,omitempty"`
1392+
ParamsJSON string `json:"params_json"`
1393+
OutputSchemaJSON string `json:"output_schema_json,omitempty"` // declared output schema, raw JSON bytes (Spec 056)
1394+
Hash string `json:"hash"`
1395+
Created time.Time `json:"created"`
1396+
Updated time.Time `json:"updated"`
1397+
Annotations *ToolAnnotations `json:"annotations,omitempty"`
13941398
}
13951399

13961400
// ToolAnnotations represents MCP tool behavior hints
@@ -1402,6 +1406,34 @@ type ToolAnnotations struct {
14021406
OpenWorldHint *bool `json:"openWorldHint,omitempty"`
14031407
}
14041408

1409+
// ToolOverride represents user-defined custom metadata for a tool.
1410+
type ToolOverride struct {
1411+
Description string `json:"description,omitempty" mapstructure:"description"`
1412+
Annotations *ToolAnnotations `json:"annotations,omitempty" mapstructure:"annotations"`
1413+
}
1414+
1415+
// ResolveToolOverride resolves a tool's effective description and annotations considering manual overrides.
1416+
func (s *ServerConfig) ResolveToolOverride(toolName string, upstreamDesc string, upstreamAnn *ToolAnnotations) (desc string, ann *ToolAnnotations, isCustom bool) {
1417+
desc = upstreamDesc
1418+
ann = upstreamAnn
1419+
if s == nil || len(s.ToolOverrides) == 0 {
1420+
return desc, ann, false
1421+
}
1422+
override, ok := s.ToolOverrides[toolName]
1423+
if !ok || override == nil {
1424+
return desc, ann, false
1425+
}
1426+
if override.Description != "" {
1427+
desc = override.Description
1428+
isCustom = true
1429+
}
1430+
if override.Annotations != nil {
1431+
ann = override.Annotations
1432+
isCustom = true
1433+
}
1434+
return desc, ann, isCustom
1435+
}
1436+
14051437
// IntentDeclarationConfig controls intent validation behavior for tool calls
14061438
type IntentDeclarationConfig struct {
14071439
// StrictServerValidation controls whether server annotation mismatches

‎internal/config/merge.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,19 @@ func CopyServerConfig(src *ServerConfig) *ServerConfig {
639639
dst.Headers[k] = v
640640
}
641641
}
642+
if src.ToolOverrides != nil {
643+
dst.ToolOverrides = make(map[string]*ToolOverride, len(src.ToolOverrides))
644+
for k, v := range src.ToolOverrides {
645+
if v != nil {
646+
overrideCopy := *v
647+
if v.Annotations != nil {
648+
annCopy := *v.Annotations
649+
overrideCopy.Annotations = &annCopy
650+
}
651+
dst.ToolOverrides[k] = &overrideCopy
652+
}
653+
}
654+
}
642655

643656
// Copy *bool by value (not pointer) to avoid shared state (MCP-2930)
644657
if src.AutoApproveToolChanges != nil {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package config
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestResolveToolOverride(t *testing.T) {
10+
readOnlyTrue := true
11+
readOnlyFalse := false
12+
destrTrue := true
13+
14+
sc := &ServerConfig{
15+
ToolOverrides: map[string]*ToolOverride{
16+
"search_issues": {
17+
Description: "Custom search description",
18+
Annotations: &ToolAnnotations{
19+
ReadOnlyHint: &readOnlyTrue,
20+
},
21+
},
22+
"delete_all": {
23+
Annotations: &ToolAnnotations{
24+
DestructiveHint: &destrTrue,
25+
ReadOnlyHint: &readOnlyFalse,
26+
},
27+
},
28+
},
29+
}
30+
31+
t.Run("overridden description and annotation", func(t *testing.T) {
32+
desc, ann, isCustom := sc.ResolveToolOverride("search_issues", "Original desc", nil)
33+
assert.True(t, isCustom)
34+
assert.Equal(t, "Custom search description", desc)
35+
assert.NotNil(t, ann)
36+
assert.Equal(t, &readOnlyTrue, ann.ReadOnlyHint)
37+
})
38+
39+
t.Run("overridden annotations only preserves original description", func(t *testing.T) {
40+
desc, ann, isCustom := sc.ResolveToolOverride("delete_all", "Original delete desc", nil)
41+
assert.True(t, isCustom)
42+
assert.Equal(t, "Original delete desc", desc)
43+
assert.NotNil(t, ann)
44+
assert.Equal(t, &destrTrue, ann.DestructiveHint)
45+
assert.Equal(t, &readOnlyFalse, ann.ReadOnlyHint)
46+
})
47+
48+
t.Run("non-overridden tool returns upstream defaults", func(t *testing.T) {
49+
upstreamAnn := &ToolAnnotations{ReadOnlyHint: &readOnlyTrue}
50+
desc, ann, isCustom := sc.ResolveToolOverride("unrelated_tool", "Upstream desc", upstreamAnn)
51+
assert.False(t, isCustom)
52+
assert.Equal(t, "Upstream desc", desc)
53+
assert.Equal(t, upstreamAnn, ann)
54+
})
55+
56+
t.Run("nil server config or nil overrides", func(t *testing.T) {
57+
var nilSc *ServerConfig
58+
desc, ann, isCustom := nilSc.ResolveToolOverride("any", "Original", nil)
59+
assert.False(t, isCustom)
60+
assert.Equal(t, "Original", desc)
61+
assert.Nil(t, ann)
62+
})
63+
}

0 commit comments

Comments
 (0)