Class McpServer.SyncSpec

java.lang.Object
io.modelcontextprotocol.server.McpServer.SyncSpec
Enclosing interface:
McpServer

@Deprecated public static class McpServer.SyncSpec extends Object
Deprecated.
Synchronous server specification.
  • Method Details

    • serverInfo

      public McpServer.SyncSpec serverInfo(McpSchema.Implementation serverInfo)
      Deprecated.
      Sets the server implementation information that will be shared with clients during connection initialization. This helps with version compatibility, debugging, and server identification.
      Parameters:
      serverInfo - The server implementation details including name and version. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if serverInfo is null
    • serverInfo

      public McpServer.SyncSpec serverInfo(String name, String version)
      Deprecated.
      Sets the server implementation information using name and version strings. This is a convenience method alternative to serverInfo(McpSchema.Implementation).
      Parameters:
      name - The server name. Must not be null or empty.
      version - The server version. Must not be null or empty.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if name or version is null or empty
      See Also:
    • capabilities

      public McpServer.SyncSpec capabilities(McpSchema.ServerCapabilities serverCapabilities)
      Deprecated.
      Sets the server capabilities that will be advertised to clients during connection initialization. Capabilities define what features the server supports, such as:
      • Tool execution
      • Resource access
      • Prompt handling
      • Streaming responses
      • Batch operations
      Parameters:
      serverCapabilities - The server capabilities configuration. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if serverCapabilities is null
    • tool

      Deprecated.
      Adds a single tool with its implementation handler to the server. This is a convenience method for registering individual tools without creating a McpServerFeatures.SyncToolRegistration explicitly.

      Example usage:

      
       .tool(
           new Tool("calculator", "Performs calculations", schema),
           args -> new CallToolResult("Result: " + calculate(args))
       )
       
      Parameters:
      tool - The tool definition including name, description, and schema. Must not be null.
      handler - The function that implements the tool's logic. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if tool or handler is null
    • tools

      Deprecated.
      Adds multiple tools with their handlers to the server using a List. This method is useful when tools are dynamically generated or loaded from a configuration source.
      Parameters:
      toolRegistrations - The list of tool registrations to add. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if toolRegistrations is null
      See Also:
    • tools

      public McpServer.SyncSpec tools(McpServerFeatures.SyncToolRegistration... toolRegistrations)
      Deprecated.
      Adds multiple tools with their handlers to the server using varargs. This method provides a convenient way to register multiple tools inline.

      Example usage:

      
       .tools(
           new ToolRegistration(calculatorTool, calculatorHandler),
           new ToolRegistration(weatherTool, weatherHandler),
           new ToolRegistration(fileManagerTool, fileManagerHandler)
       )
       
      Parameters:
      toolRegistrations - The tool registrations to add. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if toolRegistrations is null
      See Also:
    • resources

      public McpServer.SyncSpec resources(Map<String,McpServerFeatures.SyncResourceRegistration> resourceRegsitrations)
      Deprecated.
      Registers multiple resources with their handlers using a Map. This method is useful when resources are dynamically generated or loaded from a configuration source.
      Parameters:
      resourceRegsitrations - Map of resource name to registration. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if resourceRegsitrations is null
      See Also:
    • resources

      public McpServer.SyncSpec resources(List<McpServerFeatures.SyncResourceRegistration> resourceRegsitrations)
      Deprecated.
      Registers multiple resources with their handlers using a List. This method is useful when resources need to be added in bulk from a collection.
      Parameters:
      resourceRegsitrations - List of resource registrations. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if resourceRegsitrations is null
      See Also:
    • resources

      public McpServer.SyncSpec resources(McpServerFeatures.SyncResourceRegistration... resourceRegistrations)
      Deprecated.
      Registers multiple resources with their handlers using varargs. This method provides a convenient way to register multiple resources inline.

      Example usage:

      
       .resources(
           new ResourceRegistration(fileResource, fileHandler),
           new ResourceRegistration(dbResource, dbHandler),
           new ResourceRegistration(apiResource, apiHandler)
       )
       
      Parameters:
      resourceRegistrations - The resource registrations to add. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if resourceRegistrations is null
    • resourceTemplates

      public McpServer.SyncSpec resourceTemplates(List<McpSchema.ResourceTemplate> resourceTemplates)
      Deprecated.
      Sets the resource templates that define patterns for dynamic resource access. Templates use URI patterns with placeholders that can be filled at runtime.

      Example usage:

      
       .resourceTemplates(
           new ResourceTemplate("file://{path}", "Access files by path"),
           new ResourceTemplate("db://{table}/{id}", "Access database records")
       )
       
      Parameters:
      resourceTemplates - List of resource templates. If null, clears existing templates.
      Returns:
      This builder instance for method chaining
      See Also:
    • resourceTemplates

      public McpServer.SyncSpec resourceTemplates(McpSchema.ResourceTemplate... resourceTemplates)
      Deprecated.
      Sets the resource templates using varargs for convenience. This is an alternative to resourceTemplates(List).
      Parameters:
      resourceTemplates - The resource templates to set.
      Returns:
      This builder instance for method chaining
      See Also:
    • prompts

      Deprecated.
      Registers multiple prompts with their handlers using a Map. This method is useful when prompts are dynamically generated or loaded from a configuration source.

      Example usage:

      
       Map<String, PromptRegistration> prompts = new HashMap<>();
       prompts.put("analysis", new PromptRegistration(
           new Prompt("analysis", "Code analysis template"),
           request -> new GetPromptResult(generateAnalysisPrompt(request))
       ));
       .prompts(prompts)
       
      Parameters:
      prompts - Map of prompt name to registration. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if prompts is null
    • prompts

      Deprecated.
      Registers multiple prompts with their handlers using a List. This method is useful when prompts need to be added in bulk from a collection.
      Parameters:
      prompts - List of prompt registrations. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if prompts is null
      See Also:
    • prompts

      Deprecated.
      Registers multiple prompts with their handlers using varargs. This method provides a convenient way to register multiple prompts inline.

      Example usage:

      
       .prompts(
           new PromptRegistration(analysisPrompt, analysisHandler),
           new PromptRegistration(summaryPrompt, summaryHandler),
           new PromptRegistration(reviewPrompt, reviewHandler)
       )
       
      Parameters:
      prompts - The prompt registrations to add. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if prompts is null
    • rootsChangeConsumer

      public McpServer.SyncSpec rootsChangeConsumer(Consumer<List<McpSchema.Root>> consumer)
      Deprecated.
      Registers a consumer that will be notified when the list of roots changes. This is useful for updating resource availability dynamically, such as when new files are added or removed.
      Parameters:
      consumer - The consumer to register. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if consumer is null
    • rootsChangeConsumers

      public McpServer.SyncSpec rootsChangeConsumers(List<Consumer<List<McpSchema.Root>>> consumers)
      Deprecated.
      Registers multiple consumers that will be notified when the list of roots changes. This method is useful when multiple consumers need to be registered at once.
      Parameters:
      consumers - The list of consumers to register. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if consumers is null
    • rootsChangeConsumers

      public McpServer.SyncSpec rootsChangeConsumers(Consumer<List<McpSchema.Root>>... consumers)
      Deprecated.
      Registers multiple consumers that will be notified when the list of roots changes using varargs. This method provides a convenient way to register multiple consumers inline.
      Parameters:
      consumers - The consumers to register. Must not be null.
      Returns:
      This builder instance for method chaining
      Throws:
      IllegalArgumentException - if consumers is null
    • build

      public McpSyncServer build()
      Deprecated.
      Builds a synchronous MCP server that provides blocking operations.
      Returns:
      A new instance of McpSyncServer configured with this builder's settings