Skip to content

Commit 6184030

Browse files
nizzlenitzclaude
andcommitted
test(mcp): lock in over-length rejection + unlisted-v4 readability
Turn two /verify observations into assertions: - answer rejects an over-length (1200-char) question via validateQuestion's MAX_QUESTION cap, before any retrieve/generate. - resources/list omits legacy v4, but a v4 page still reads through the template — listing is discovery, not an allowlist. Both verified live on :9936. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Eijma5uKcPZi9tqV2aJBeh
1 parent 1d6a9de commit 6184030

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

app/test/integration/mcp.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ test('MCP answer tool returns a grounded answer with citations', async (t) => {
9494

9595
const bad = await call('answer', {});
9696
assert.equal(bad.body.result.isError, true, 'missing question is a tool error');
97+
98+
// validateQuestion caps length at MAX_QUESTION (1000) — an over-length question
99+
// is rejected before any retrieve/generate, so no unbounded input reaches the model.
100+
const long = await call('answer', { question: 'a '.repeat(600) }); // 1200 chars
101+
assert.equal(long.body.result.isError, true, 'over-length question is rejected');
97102
});
98103

99104
test('MCP resources: template, list from nav, read a page, bad uri → -32002', async (t) => {
@@ -112,6 +117,12 @@ test('MCP resources: template, list from nav, read a page, bad uri → -32002',
112117

113118
const missing = await rpc({ jsonrpc: '2.0', id: 4, method: 'resources/read', params: { uri: 'harper-docs:///nope/nope' } });
114119
assert.equal(missing.body.error.code, -32002, 'missing resource → -32002');
120+
121+
// resources/list only enumerates the current reference version (v5), but legacy
122+
// v4 pages stay readable via the template — listing is discovery, not an allowlist.
123+
assert.ok(!resources.some((r) => r.uri.includes('reference/v4')), 'v4 is not enumerated');
124+
const v4 = await rpc({ jsonrpc: '2.0', id: 5, method: 'resources/read', params: { uri: 'harper-docs:///reference/v4/cli/commands' } });
125+
assert.match(v4.body.result.contents[0].text, /^# /, 'unlisted v4 page still reads via the template');
115126
});
116127

117128
test('MCP rejects batches, and answers an id:null request (not as a notification)', async (t) => {

0 commit comments

Comments
 (0)