@getnote/mcp 1.8.0 → 1.9.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/.github/workflows/release.yml +2 -2
- package/README.md +11 -0
- package/dist/client.d.ts +106 -25
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +18 -7
- package/dist/discovery.d.ts +101 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +124 -0
- package/dist/index.js +52 -7
- package/package.json +1 -1
- package/src/client.ts +73 -27
- package/src/discovery.ts +91 -0
- package/src/index.ts +41 -7
- package/test/client.test.mjs +13 -0
- package/test/discovery-validation.test.mjs +19 -0
- package/test/discovery.test.mjs +70 -0
- package/test/original.test.mjs +46 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { discoveryContract, verifyDiscovery } from '../dist/discovery.js';
|
|
4
|
+
|
|
5
|
+
test('discovery normalizes lookup and nanosecond intervals without altering source identity',()=>{
|
|
6
|
+
const c=discoveryContract('notes',{source:'dedao',reference_resource_type:'course_article',reference_resource_id:'9007199254740993',reference_article_url:'https://example.invalid/a?x=1#p',created_from:'2026-10-09T11:00:00.000000001+08:00',created_to:'2026-10-09T03:00:00.000000002Z'});
|
|
7
|
+
assert.equal(c.params.created_from,'2026-10-09T03:00:00.000000001Z');assert.equal(c.params.reference_resource_id,'9007199254740993');assert.equal(c.params.reference_article_url,'https://example.invalid/a?x=1#p');
|
|
8
|
+
const k=discoveryContract('topics',{scope:'BOOKSPACE',query:' 《AI 书》 ',author:' “作者” '});assert.equal(k.filters.query,'ai 书');assert.equal(k.filters.author,'作者');
|
|
9
|
+
for(const args of [{created_from:'2026-02-30T00:00:00Z'},{created_from:'2026-10-09T11:00:00'},{page_size:0},{page_size:101},{page:2},{topic_id:'t',page:2,cursor:'x'},{reference_resource_id:'9007199254740993'},{source:'dedao',reference_resource_type:'ebook',reference_resource_id:'9223372036854775808'},{created_from:'2026-10-09T03:00:00.000000002Z',created_to:'2026-10-09T03:00:00.000000001Z'}])assert.throws(()=>discoveryContract('notes',args),JSON.stringify(args));
|
|
10
|
+
assert.throws(()=>discoveryContract('topics',{author:'作者'}));
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('new contract fails closed for missing capability, filters, counts and continuation',()=>{
|
|
14
|
+
const c=discoveryContract('notes',{topic_id:'topic-x'});
|
|
15
|
+
const base={meta:{capabilities:['note.filters.v1','pagination.v1','note.reference.v1']},data:{notes:[],applied_filters:{topic_id:'topic-x'},pagination:{mode:'cursor',page:null,page_size:20,returned_count:0,total_count:null,has_more:false,next_cursor:null,next_page:null}}};
|
|
16
|
+
verifyDiscovery(base,c);
|
|
17
|
+
const changes=[x=>delete x.meta,x=>delete x.data.applied_filters,x=>x.data.applied_filters.topic_id='other',x=>x.data.pagination.returned_count=1,x=>delete x.data.pagination.total_count,x=>x.data.pagination.has_more=true,x=>x.data.pagination.next_cursor='stale',x=>x.meta.capabilities=x.meta.capabilities.filter(v=>v!=='note.reference.v1')];
|
|
18
|
+
for(const change of changes){const x=structuredClone(base);change(x);assert.throws(()=>verifyDiscovery(x,c));}
|
|
19
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
import test from 'node:test';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
6
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
7
|
+
|
|
8
|
+
// Exercise the registered schema and real stdio tool handler through HTTP.
|
|
9
|
+
test('discovery tools forward selectors and reject false capability success', async () => {
|
|
10
|
+
let mode='supported';let received;
|
|
11
|
+
const api=http.createServer((req,res)=>{
|
|
12
|
+
const url=new URL(req.url,'http://localhost');received=Object.fromEntries(url.searchParams);
|
|
13
|
+
const filters=Object.fromEntries([...url.searchParams].filter(([key])=>!['page','page_size','cursor','id','image_quality'].includes(key)));
|
|
14
|
+
if(url.pathname.endsWith('/knowledge/subscribe/list')) filters.exclude_mine=true;
|
|
15
|
+
if(mode==='ignored')delete filters.note_type;
|
|
16
|
+
res.setHeader('content-type','application/json');
|
|
17
|
+
res.end(JSON.stringify({success:true,meta:{capabilities:mode==='old'?[]:['note.filters.v1','pagination.v1','note.reference.v1','knowledge.lookup.v1']},data:{notes:[],topics:[],note:{note_id:'9007199254740993',title:'',content_state:{content:'omitted',ref_content:'omitted'}},pagination:{mode:url.searchParams.has('page')?'page':'cursor',page:Number(url.searchParams.get('page')||1),page_size:Number(url.searchParams.get('page_size')||20),returned_count:0,total_count:null,has_more:false,next_cursor:null,next_page:null},applied_filters:filters}}));
|
|
18
|
+
});
|
|
19
|
+
await new Promise(resolve=>api.listen(0,'127.0.0.1',resolve));
|
|
20
|
+
const client=new Client({name:'discovery-contract',version:'1'});
|
|
21
|
+
const transport=new StdioClientTransport({command:process.execPath,args:[fileURLToPath(new URL('../dist/index.js',import.meta.url))],env:{...process.env,GETNOTE_API_KEY:'synthetic',GETNOTE_CLIENT_ID:'synthetic',GETNOTE_API_URL:`http://127.0.0.1:${api.address().port}`},stderr:'pipe'});
|
|
22
|
+
try {
|
|
23
|
+
await client.connect(transport);
|
|
24
|
+
const {tools}=await client.listTools();
|
|
25
|
+
const schemas=Object.fromEntries(tools.map(t=>[t.name,t.inputSchema.properties]));
|
|
26
|
+
for(const key of ['source','note_type','reference_resource_type','reference_resource_id','reference_article_url','topic_id','created_from','created_to','edited_from','edited_to','record_updated_from','record_updated_to','page_size'])assert.ok(schemas.list_notes[key],`missing list_notes schema: ${key}`);
|
|
27
|
+
for(const key of ['query','author','book_id','page_size'])assert.ok(schemas.list_topics[key],`missing lookup schema: ${key}`);
|
|
28
|
+
const selectors={source:'dedao',note_type:'ref',reference_resource_type:'course_article',reference_resource_id:'9007199254740993',reference_article_url:'https://example.invalid/a?x=1#p',created_from:'2026-10-09T03:00:00Z',page_size:7};
|
|
29
|
+
for(const [name,args] of [['list_notes',selectors],['list_topic_notes',{...selectors,topic_id:'topic-x',page:2}],['list_topics',{scope:'BOOKSPACE',query:'书名',author:'作者',book_id:'book-x',page_size:7}],['list_subscribe_topics',{scope:'BOOKSPACE',query:'书名',author:'作者',page_size:7}],['get_note',{id:'9007199254740993'}]]) {
|
|
30
|
+
const result=await client.callTool({name,arguments:args});assert.ok(!result.isError,result.content[0].text);
|
|
31
|
+
for(const [key,value]of Object.entries(args))assert.equal(received[key],String(value),`${name}.${key}`);
|
|
32
|
+
assert.ok(JSON.parse(result.content[0].text).meta.capabilities.includes('note.reference.v1'));
|
|
33
|
+
if(name==='list_subscribe_topics') assert.equal(JSON.parse(result.content[0].text).applied_filters.exclude_mine,true);
|
|
34
|
+
}
|
|
35
|
+
for(const bad of ['old','ignored']) {
|
|
36
|
+
mode=bad;const result=await client.callTool({name:'list_notes',arguments:selectors});assert.equal(result.isError,true,`${bad} must not return filtered success`);
|
|
37
|
+
}
|
|
38
|
+
mode='old';const legacy=await client.callTool({name:'list_notes',arguments:{cursor:'legacy-opaque'}});assert.ok(!legacy.isError,'legacy call must still work');
|
|
39
|
+
mode='supported';const bad=await client.callTool({name:'list_notes',arguments:{page_size:0}});assert.equal(bad.isError,true,'zero page_size invalid');
|
|
40
|
+
}finally{await client.close();api.closeAllConnections();await new Promise(resolve=>api.close(resolve));}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('typed subscription flags preserve strict requested filter validation', async () => {
|
|
44
|
+
const { discoveryContract, verifyDiscovery } = await import('../dist/discovery.js');
|
|
45
|
+
const contract = discoveryContract('topics', { scope:'BOOKSPACE', author:'作者', page_size:2 });
|
|
46
|
+
const body = {meta:{capabilities:['knowledge.lookup.v1','pagination.v1']}, data:{topics:[], applied_filters:{scope:'BOOKSPACE',author:'作者',exclude_mine:true,future_flag:false,future_value:null},pagination:{mode:'page',page:1,page_size:2,returned_count:0,total_count:0,has_more:false,next_page:null,next_cursor:null}}};
|
|
47
|
+
assert.doesNotThrow(()=>verifyDiscovery(body,contract));
|
|
48
|
+
for(const value of [undefined,null,true,42,'其他作者']) {
|
|
49
|
+
const bad=structuredClone(body); bad.data.applied_filters.author=value;
|
|
50
|
+
assert.throws(()=>verifyDiscovery(bad,contract),/server did not apply author/);
|
|
51
|
+
}
|
|
52
|
+
for(const value of [undefined,null,[],true,'filters']) {
|
|
53
|
+
const bad=structuredClone(body); bad.data.applied_filters=value;
|
|
54
|
+
assert.throws(()=>verifyDiscovery(bad,contract),/applied_filters/);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Knowledge lookup does not return note references and must not require that capability.
|
|
59
|
+
test('knowledge lookup accepts the deployed knowledge capability contract', async () => {
|
|
60
|
+
const { discoveryContract, verifyDiscovery } = await import('../dist/discovery.js');
|
|
61
|
+
const contract = discoveryContract('topics', { scope: 'BOOKSPACE', page_size: 2 });
|
|
62
|
+
assert.deepEqual(contract.capabilities, ['pagination.v1', 'knowledge.lookup.v1']);
|
|
63
|
+
assert.doesNotThrow(() => verifyDiscovery({
|
|
64
|
+
meta: { capabilities: ['knowledge.lookup.v1', 'pagination.v1'] },
|
|
65
|
+
data: { topics: [], applied_filters: { scope: 'BOOKSPACE' }, pagination: {
|
|
66
|
+
mode: 'page', page: 1, page_size: 2, returned_count: 0, total_count: 0,
|
|
67
|
+
has_more: false, next_page: null, next_cursor: null
|
|
68
|
+
} }
|
|
69
|
+
}, contract));
|
|
70
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
import test from 'node:test';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
6
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
7
|
+
|
|
8
|
+
test('get_note_original uses only the source selected by note_type', async () => {
|
|
9
|
+
const cases = [
|
|
10
|
+
{ note_type: 'ref', content: 'personal comment', ref_content: 'quoted passage', want: 'quoted passage', source: 'ref_content' },
|
|
11
|
+
{ note_type: 'ref', content: '', ref_content: 'quoted passage', want: 'quoted passage', source: 'ref_content' },
|
|
12
|
+
{ note_type: 'ref', content: 'personal comment', ref_content: '', error: true },
|
|
13
|
+
{ note_type: 'plain_text', content: 'typed text', ref_content: 'other', want: 'typed text', source: 'content' },
|
|
14
|
+
{ note_type: 'link', content: 'AI summary', web_page: {url:'https://example.test',content:'web article'}, want: 'web article', source: 'web_page.content' },
|
|
15
|
+
{ note_type: 'audio', content: 'AI summary', audio: {original:'raw transcript'}, want: 'raw transcript', source: 'audio.original' },
|
|
16
|
+
{ note_type: 'local_audio', content: 'AI summary', audio: {original:'local raw transcript'}, want: 'local raw transcript', source: 'audio.original' },
|
|
17
|
+
{ note_type: 'unknown', content: 'AI summary', error: true },
|
|
18
|
+
];
|
|
19
|
+
let current = cases[0];
|
|
20
|
+
const api = http.createServer((_req, res) => {
|
|
21
|
+
res.setHeader('content-type', 'application/json');
|
|
22
|
+
res.end(JSON.stringify({success:true,data:{note:{id:'123',title:'Synthetic',source:'manual',tags:[],created_at:'',updated_at:'',...current}}}));
|
|
23
|
+
});
|
|
24
|
+
await new Promise(resolve => api.listen(0, '127.0.0.1', resolve));
|
|
25
|
+
const client = new Client({name:'original-regression',version:'1'});
|
|
26
|
+
const transport = new StdioClientTransport({command:process.execPath,args:[fileURLToPath(new URL('../dist/index.js',import.meta.url))],env:{...process.env,GETNOTE_API_KEY:'test-key',GETNOTE_CLIENT_ID:'test-client',GETNOTE_API_URL:`http://127.0.0.1:${api.address().port}`},stderr:'pipe'});
|
|
27
|
+
try {
|
|
28
|
+
await client.connect(transport);
|
|
29
|
+
for (const fixture of cases) {
|
|
30
|
+
current = fixture;
|
|
31
|
+
const response = await client.callTool({name:'get_note_original',arguments:{id:'123'}});
|
|
32
|
+
if (fixture.error) {
|
|
33
|
+
assert.equal(response.isError, true, fixture.note_type);
|
|
34
|
+
assert.match(response.content[0].text, /not available|unsupported/i);
|
|
35
|
+
} else {
|
|
36
|
+
assert.ok(!response.isError, fixture.note_type);
|
|
37
|
+
const data = JSON.parse(response.content[0].text);
|
|
38
|
+
assert.deepEqual(data, {id:'123',note_type:fixture.note_type,title:'Synthetic',original:fixture.want,original_source:fixture.source});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} finally {
|
|
42
|
+
await client.close();
|
|
43
|
+
api.closeAllConnections();
|
|
44
|
+
await new Promise(resolve => api.close(resolve));
|
|
45
|
+
}
|
|
46
|
+
});
|