@@ -298,6 +298,7 @@ const handler = async (req: Request) => {
298298 // Execute MCP handler and capture response
299299 const mcpResponse = await createMcpHandler (
300300 ( server ) => {
301+ // Tool 1: Add Numbers
301302 server . tool (
302303 "add_numbers" ,
303304 "Adds two numbers together and returns the sum" ,
@@ -316,6 +317,136 @@ const handler = async (req: Request) => {
316317 } ;
317318 }
318319 ) ;
320+
321+ // Tool 2: Calculate Circle Area
322+ server . tool (
323+ "calculate_circle_area" ,
324+ "Calculates the area of a circle given its radius" ,
325+ {
326+ radius : z . number ( ) . positive ( ) . describe ( "Radius of the circle" ) ,
327+ } ,
328+ async ( { radius } ) => {
329+ const area = Math . PI * radius * radius ;
330+ return {
331+ content : [
332+ {
333+ type : "text" ,
334+ text : `A circle with radius ${ radius } has an area of ${ area . toFixed ( 2 ) } square units` ,
335+ } ,
336+ ] ,
337+ } ;
338+ }
339+ ) ;
340+
341+ // Tool 3: Generate Random Number
342+ server . tool (
343+ "generate_random_number" ,
344+ "Generates a random number within a specified range" ,
345+ {
346+ min : z . number ( ) . describe ( "Minimum value (inclusive)" ) ,
347+ max : z . number ( ) . describe ( "Maximum value (inclusive)" ) ,
348+ } ,
349+ async ( { min, max } ) => {
350+ if ( min > max ) {
351+ return {
352+ content : [
353+ {
354+ type : "text" ,
355+ text : "Error: Minimum value cannot be greater than maximum value" ,
356+ } ,
357+ ] ,
358+ } ;
359+ }
360+ const randomNum = Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
361+ return {
362+ content : [
363+ {
364+ type : "text" ,
365+ text : `Random number between ${ min } and ${ max } : ${ randomNum } ` ,
366+ } ,
367+ ] ,
368+ } ;
369+ }
370+ ) ;
371+
372+ // Tool 4: Format Text
373+ server . tool (
374+ "format_text" ,
375+ "Formats text with various options like uppercase, lowercase, or title case" ,
376+ {
377+ text : z . string ( ) . describe ( "Text to format" ) ,
378+ format : z . enum ( [ "uppercase" , "lowercase" , "titlecase" , "reverse" ] ) . describe ( "Format type" ) ,
379+ } ,
380+ async ( { text, format } ) => {
381+ let formattedText : string ;
382+
383+ switch ( format ) {
384+ case "uppercase" :
385+ formattedText = text . toUpperCase ( ) ;
386+ break ;
387+ case "lowercase" :
388+ formattedText = text . toLowerCase ( ) ;
389+ break ;
390+ case "titlecase" :
391+ formattedText = text . replace ( / \w \S * / g, ( txt ) =>
392+ txt . charAt ( 0 ) . toUpperCase ( ) + txt . substr ( 1 ) . toLowerCase ( )
393+ ) ;
394+ break ;
395+ case "reverse" :
396+ formattedText = text . split ( '' ) . reverse ( ) . join ( '' ) ;
397+ break ;
398+ default :
399+ formattedText = text ;
400+ }
401+
402+ return {
403+ content : [
404+ {
405+ type : "text" ,
406+ text : `Original: "${ text } "\nFormatted (${ format } ): "${ formattedText } "` ,
407+ } ,
408+ ] ,
409+ } ;
410+ }
411+ ) ;
412+
413+ // Tool 5: Check Prime Number
414+ server . tool (
415+ "check_prime_number" ,
416+ "Checks if a given number is prime" ,
417+ {
418+ number : z . number ( ) . int ( ) . positive ( ) . describe ( "Number to check for primality" ) ,
419+ } ,
420+ async ( { number } ) => {
421+ if ( number < 2 ) {
422+ return {
423+ content : [
424+ {
425+ type : "text" ,
426+ text : `${ number } is not a prime number (must be 2 or greater)` ,
427+ } ,
428+ ] ,
429+ } ;
430+ }
431+
432+ let isPrime = true ;
433+ for ( let i = 2 ; i <= Math . sqrt ( number ) ; i ++ ) {
434+ if ( number % i === 0 ) {
435+ isPrime = false ;
436+ break ;
437+ }
438+ }
439+
440+ return {
441+ content : [
442+ {
443+ type : "text" ,
444+ text : `${ number } is ${ isPrime ? 'a prime' : 'not a prime' } number` ,
445+ } ,
446+ ] ,
447+ } ;
448+ }
449+ ) ;
319450 } ,
320451 {
321452 // Optionally add server capabilities here
0 commit comments