@@ -393,53 +393,53 @@ const server = new McpServer({
393393 version: " 1.0.0"
394394});
395395
396- server .tool (
396+ const listMessageTool = server .tool (
397397 " listMessages" ,
398398 { channel: z .string () },
399399 async ({ channel }) => ({
400400 content: [{ type: " text" , text: await listMessages (channel ) }]
401401 })
402402);
403403
404- server .tool (
404+ const putMessageTool = server .tool (
405+ " putMessage" ,
406+ { channel: z .string (), message: z .string () },
407+ async ({ channel , message }) => ({
408+ content: [{ type: " text" , text: await putMessage (channel , string ) }]
409+ })
410+ );
411+ // Until we upgrade auth, `putMessage` is disabled (won't show up in listTools)
412+ putMessageTool .disable ()
413+
414+ const upgradeAuthTool = server .tool (
405415 " upgradeAuth" ,
406416 { permission: z .enum ([" write', vadmin" ])},
407- upgradeAuth
408- )
409-
410- // Connect with the existing set of tools
411- const transport = new StdioServerTransport ();
412- await server .connect (transport );
413-
414- // Any mutations after connection result in `listChanged` notifications so the client knows to refresh
415- async function upgradeAuth({permission }) {
416- const { ok, err, previous } = await upgradeAuthAndStoreToken (permission )
417-
418- if (! ok ) return {content: [{ type: " text" , text: ` Error: ${err } ` }]}
417+ // Any mutations here will automatically emit `listChanged` notifications
418+ async ({ permission }) => {
419+ const { ok, err, previous } = await upgradeAuthAndStoreToken (permission )
420+ if (! ok ) return {content: [{ type: " text" , text: ` Error: ${err } ` }]}
421+
422+ // If we previously had read-only access, 'putMessage' is now available
423+ if (previous === " read" ) {
424+ putMessageTool .enable ()
425+ }
419426
420- // If we previously had read-only access, we need to add 'putMessage' now we can use it
421- if (previous === " read" ) {
422- server .tool (
423- " putMessage" ,
424- { channel: z .string (), message: z .string () },
425- async ({ channel , message }) => ({
426- content: [{ type: " text" , text: await putMessage (channel , string ) }]
427+ if (permission === ' write' ) {
428+ // If we've just upgraded to 'write' permissions, we can still call 'upgradeAuth'
429+ // but can only upgrade to 'admin'.
430+ upgradeAuthTool .update ({
431+ paramSchema: { permission: z .enum ([" admin" ]) }, // change validation rules
427432 })
428- );
433+ } else {
434+ // If we're now an admin, we no longer have anywhere to upgrade to, so fully remove that tool
435+ upgradeAuthTool .remove ()
436+ }
429437 }
438+ )
430439
431- // If we've just upgraded to 'write' permissions, we can still call 'upgradeAuth' but can only upgrade to 'admin'
432- if (permission === ' write' ) {
433- server .updateTool (
434- " upgradeAuth" ,
435- { permission: z .enum ([" admin" ])}, // change param validation
436- upgradeAuth
437- )
438- } else {
439- // If we're on admin, we no longer have anywhere to upgrade to
440- server .removeTool (" upgradeAuth" )
441- }
442- }
440+ // Connect as normal
441+ const transport = new StdioServerTransport ();
442+ await server .connect (transport );
443443```
444444
445445### Low-Level Server
0 commit comments