Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/everything/resources/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const RESOURCE_TYPES: string[] = [
* The completion logic matches the input against available resource types.
*/
export const resourceTypeCompleter = completable(
z.string().describe("Type of resource to fetch"),
z.string().describe("Type of resource — must be 'Text' or 'Blob'"),
(value: string) => {
return RESOURCE_TYPES.filter((t) => t.startsWith(value));
}
Expand Down
34 changes: 29 additions & 5 deletions src/everything/tools/get-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,50 @@ const name = "get-env";
const config = {
title: "Print Environment Tool",
description:
"Returns all environment variables, helpful for debugging MCP server configuration",
inputSchema: {},
"Returns the value of a specific environment variable, helpful for debugging MCP server configuration",
inputSchema: {
type: "object",
properties: {
key: {
type: "string",
description:
"The name of the environment variable to retrieve (e.g., 'PATH', 'HOME', 'USER')",
},
},
required: ["key"],
},
};

/**
* Registers the 'get-env' tool.
*
* The registered tool Retrieves and returns the environment variables
* of the current process as a JSON-formatted string encapsulated in a text response.
* The registered tool retrieves and returns the value of a specific
* environment variable from the current process.
*
* @param {McpServer} server - The McpServer instance where the tool will be registered.
* @returns {void}
*/
export const registerGetEnvTool = (server: McpServer) => {
server.registerTool(name, config, async (args): Promise<CallToolResult> => {
const { key } = args as { key: string };
const value = process.env[key];

if (value === undefined) {
return {
content: [
{
type: "text",
text: `Environment variable '${key}' is not set.`,
},
],
};
}

return {
content: [
{
type: "text",
text: JSON.stringify(process.env, null, 2),
text: `${key}=${value}`,
},
],
};
Expand Down
12 changes: 9 additions & 3 deletions src/filesystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,10 @@ async function updateAllowedDirectoriesFromRoots(requestedRoots: Root[]) {
// Handles dynamic roots updates during runtime, when client sends "roots/list_changed" notification, server fetches the updated roots and replaces all allowed directories with the new roots.
server.server.setNotificationHandler(RootsListChangedNotificationSchema, async () => {
try {
// Request the updated roots list from the client
// Only update from MCP roots if no CLI directories were set
if (allowedDirectories.length > 0) {
return;
}
const response = await server.server.listRoots();
if (response && 'roots' in response) {
await updateAllowedDirectoriesFromRoots(response.roots);
Expand All @@ -731,7 +734,10 @@ server.server.setNotificationHandler(RootsListChangedNotificationSchema, async (
server.server.oninitialized = async () => {
const clientCapabilities = server.server.getClientCapabilities();

if (clientCapabilities?.roots) {
if (clientCapabilities?.roots && allowedDirectories.length === 0) {
// Only fetch and apply MCP roots when no CLI directories were provided.
// CLI arguments take precedence over MCP roots since they are explicitly
// specified by the server operator.
try {
const response = await server.server.listRoots();
if (response && 'roots' in response) {
Expand All @@ -744,7 +750,7 @@ server.server.oninitialized = async () => {
}
} else {
if (allowedDirectories.length > 0) {
console.error("Client does not support MCP Roots, using allowed directories set from server args:", allowedDirectories);
console.error("Client does not support MCP Roots, or CLI directories provided. Using allowed directories from server args:", allowedDirectories);
}else{
throw new Error(`Server cannot operate: No allowed directories available. Server was started without command-line directories and client either does not support MCP roots protocol or provided empty roots. Please either: 1) Start server with directory arguments, or 2) Use a client that supports MCP roots protocol and provides valid root directories.`);
}
Expand Down
Loading