Class DefaultMcpResourcesAsToolsPresenter
java.lang.Object
dev.langchain4j.mcp.resourcesastools.DefaultMcpResourcesAsToolsPresenter
- All Implemented Interfaces:
McpResourcesAsToolsPresenter
public class DefaultMcpResourcesAsToolsPresenter
extends Object
implements McpResourcesAsToolsPresenter
Default implementation of
McpResourcesAsToolsPresenter.
A presenter that presents MCP resources as tools. It provides two tools: list_resources and get_resource.
The list_resources tool lists all available resources. It doesn't take any arguments and returns a JSON array where
each object represents a single resource. For example:
[ {
"mcpServer" : "alice",
"uri" : "file:///info",
"uriTemplate" : null,
"name" : "basicInfo",
"description" : "Basic information about Alice",
"mimeType" : "text/plain"
}, {
"mcpServer" : "bob",
"uri" : "file:///info",
"uriTemplate" : null,
"name" : "basicInfo",
"description" : "Basic information about Bob",
"mimeType" : "text/plain"
} ]
The get_resource tool retrieves a specific resource based on its MCP server name and URI. It takes two arguments:
mcpServer and uri. Both arguments are mandatory. For example:
The DefaultMcpResourcesAsToolsPresenter provides default names and descriptions of these two tools and their arguments. These
descriptions should generally work, but if it's necessary to override them, this can be done in the builder.-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefaultMcpResourcesAsToolsPresenter(String nameOfGetResourceTool, String descriptionOfGetResourceTool, String descriptionOfMcpServerParameterOfGetResourceTool, String descriptionOfUriParameterOfGetResourceTool, String nameOfListResourcesTool, String descriptionOfListResourcesTool) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()createGetResourceExecutor(List<McpClient> mcpClients) Create an executor for the tool that gets a particular resource.Create a specification for the tool that gets a particular resource.createListResourcesExecutor(List<McpClient> mcpClients) Create an executor for the tool that lists available resources.Create a specification for the tool that lists available resources.
-
Field Details
-
DEFAULT_NAME_OF_GET_RESOURCE_TOOL
- See Also:
-
DEFAULT_DESCRIPTION_OF_GET_RESOURCE_TOOL
- See Also:
-
DEFAULT_DESCRIPTION_OF_MCP_SERVER_PARAMETER_OF_GET_RESOURCE_TOOL
- See Also:
-
DEFAULT_DESCRIPTION_OF_URI_PARAMETER_OF_GET_RESOURCE_TOOL
- See Also:
-
DEFAULT_NAME_OF_LIST_RESOURCES_TOOL
- See Also:
-
DEFAULT_DESCRIPTION_OF_LIST_RESOURCES_TOOL
- See Also:
-
-
Constructor Details
-
DefaultMcpResourcesAsToolsPresenter
-
-
Method Details
-
createListResourcesSpecification
Description copied from interface:McpResourcesAsToolsPresenterCreate a specification for the tool that lists available resources.- Specified by:
createListResourcesSpecificationin interfaceMcpResourcesAsToolsPresenter
-
createListResourcesExecutor
Description copied from interface:McpResourcesAsToolsPresenterCreate an executor for the tool that lists available resources.- Specified by:
createListResourcesExecutorin interfaceMcpResourcesAsToolsPresenter
-
createGetResourceSpecification
Description copied from interface:McpResourcesAsToolsPresenterCreate a specification for the tool that gets a particular resource.- Specified by:
createGetResourceSpecificationin interfaceMcpResourcesAsToolsPresenter
-
createGetResourceExecutor
Description copied from interface:McpResourcesAsToolsPresenterCreate an executor for the tool that gets a particular resource.- Specified by:
createGetResourceExecutorin interfaceMcpResourcesAsToolsPresenter
-
builder
-