UNPKG

@eclipse-glsp/protocol

Version:

The protocol definition for client-server communication in GLSP

75 lines 3.88 kB
"use strict"; /******************************************************************************** * Copyright (c) 2025-2026 EclipseSource and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ Object.defineProperty(exports, "__esModule", { value: true }); exports.McpInitializeResult = exports.McpServerResult = exports.McpInitializeParameters = void 0; const type_util_1 = require("../utils/type-util"); var McpInitializeParameters; (function (McpInitializeParameters) { /** * Type guard that also doubles as the **opt-in check**: returns `true` iff `params.mcpServer` * is defined (regardless of its content). Server-side code uses this to decide whether to * start the MCP HTTP server at all. See {@link McpInitializeParameters.mcpServer} for the * opt-in semantics. */ function is(params) { return type_util_1.AnyObject.is(params) && (0, type_util_1.hasObjectProp)(params, 'mcpServer'); } McpInitializeParameters.is = is; /** * Returns the {@link McpServerConfiguration} from the given initialize parameters, or * `undefined` if MCP is not opted in (i.e., `mcpServer` is missing). A return value of `{}` * (an empty object) means "MCP is enabled, use all defaults" — distinct from `undefined` * which means "MCP is not enabled." */ function getServerConfig(params) { return is(params) ? params.mcpServer : undefined; } McpInitializeParameters.getServerConfig = getServerConfig; })(McpInitializeParameters || (exports.McpInitializeParameters = McpInitializeParameters = {})); var McpServerResult; (function (McpServerResult) { /** True when the candidate is shaped like {@link McpServerResult}. */ function is(candidate) { return type_util_1.AnyObject.is(candidate) && (0, type_util_1.hasStringProp)(candidate, 'name') && (0, type_util_1.hasStringProp)(candidate, 'url'); } McpServerResult.is = is; })(McpServerResult || (exports.McpServerResult = McpServerResult = {})); var McpInitializeResult; (function (McpInitializeResult) { /** Narrows to `McpInitializeResult` (i.e., asserts `mcpServer` is populated and well-shaped). */ function is(result) { return type_util_1.AnyObject.is(result) && (0, type_util_1.hasObjectProp)(result, 'mcpServer') && McpServerResult.is(result.mcpServer); } McpInitializeResult.is = is; /** Returns the {@link McpServerResult} from the given initialize result, or `undefined` if MCP is not announced. */ function getServer(result) { return is(result) ? result.mcpServer : undefined; } McpInitializeResult.getServer = getServer; /** * Attaches an {@link McpServerResult} announcement to a base {@link InitializeResult}, * returning the augmented {@link McpInitializeResult}. Server-side handshake code uses this * instead of an in-place cast to keep the mutation typed. */ function attachServer(result, server) { const augmented = result; augmented.mcpServer = server; return augmented; } McpInitializeResult.attachServer = attachServer; })(McpInitializeResult || (exports.McpInitializeResult = McpInitializeResult = {})); //# sourceMappingURL=mcp.js.map