add authenticate button in gui
- added a startAuthentication protocol
This commit is contained in:
parent
6a07e7b8b3
commit
a062f26559
6 changed files with 65 additions and 16 deletions
|
|
@ -117,7 +117,6 @@ class MCPConnection {
|
|||
|
||||
if (this.options.transport.type === "sse") {
|
||||
// currently support oauth for sse transports only
|
||||
console.log("debug1 extras", this.extras);
|
||||
if (!this.options.transport.requestOptions) {
|
||||
this.options.transport.requestOptions = {
|
||||
headers: {},
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import {
|
|||
OAuthTokens,
|
||||
OAuthTokensSchema,
|
||||
} from "@modelcontextprotocol/sdk/shared/auth.js";
|
||||
import { IDE } from "../..";
|
||||
import { IDE, MCPServerStatus, SSEOptions } from "../..";
|
||||
|
||||
import http from "http";
|
||||
import url from "url";
|
||||
|
|
@ -173,13 +173,12 @@ export async function getOauthToken(mcpServerUrl: string, ide: IDE) {
|
|||
return tokens?.access_token;
|
||||
}
|
||||
|
||||
// TODO: this needs to be called from an authenticate button in gui
|
||||
export async function performAuth(mcpServerUrl: string, ide: IDE) {
|
||||
export async function performAuth(mcpServer: MCPServerStatus, ide: IDE) {
|
||||
const mcpServerUrl = (mcpServer.transport as SSEOptions).url;
|
||||
const authProvider = new MCPConnectionOauthProvider(mcpServerUrl, ide);
|
||||
const result = await auth(authProvider, {
|
||||
return await auth(authProvider, {
|
||||
serverUrl: mcpServerUrl,
|
||||
});
|
||||
console.log("debug1 first result", result);
|
||||
}
|
||||
|
||||
export async function handleMCPOauthCode(
|
||||
|
|
@ -201,11 +200,8 @@ export async function handleMCPOauthCode(
|
|||
authorizationCode,
|
||||
});
|
||||
const authProvider = new MCPConnectionOauthProvider(serverUrl, ide);
|
||||
console.log("debug1 starting auth");
|
||||
const result = await auth(authProvider, {
|
||||
return await auth(authProvider, {
|
||||
serverUrl,
|
||||
authorizationCode,
|
||||
});
|
||||
|
||||
console.log("debug1 after auth result", result);
|
||||
}
|
||||
|
|
|
|||
17
core/core.ts
17
core/core.ts
|
|
@ -61,7 +61,7 @@ import {
|
|||
} from "./config/onboarding";
|
||||
import { createNewWorkspaceBlockFile } from "./config/workspace/workspaceBlocks";
|
||||
import { MCPManagerSingleton } from "./context/mcp/MCPManagerSingleton";
|
||||
import { handleMCPOauthCode } from "./context/mcp/MCPOauth";
|
||||
import { handleMCPOauthCode, performAuth } from "./context/mcp/MCPOauth";
|
||||
import { setMdmLicenseKey } from "./control-plane/mdm/mdm";
|
||||
import { ApplyAbortManager } from "./edit/applyAbortManager";
|
||||
import { streamDiffLines } from "./edit/streamDiffLines";
|
||||
|
|
@ -434,8 +434,21 @@ export class Core {
|
|||
description: prompt.description,
|
||||
};
|
||||
});
|
||||
on("mcp/startAuthentication", async (msg) => {
|
||||
const status = await performAuth(msg.data, this.ide);
|
||||
if (status === "AUTHORIZED") {
|
||||
await MCPManagerSingleton.getInstance().refreshConnection(msg.data.id);
|
||||
}
|
||||
});
|
||||
on("mcp/sendOauthCode", async (msg) => {
|
||||
await handleMCPOauthCode(msg.data.code, this.ide, this.messenger);
|
||||
const status = await handleMCPOauthCode(
|
||||
msg.data.code,
|
||||
this.ide,
|
||||
this.messenger,
|
||||
);
|
||||
if (status === "AUTHORIZED") {
|
||||
// await MCPManagerSingleton.getInstance().refreshConnection(msg.data.id);
|
||||
}
|
||||
});
|
||||
|
||||
// Context providers
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import {
|
|||
FileSymbolMap,
|
||||
IdeSettings,
|
||||
LLMFullCompletionOptions,
|
||||
MCPServerStatus,
|
||||
MessageOption,
|
||||
ModelDescription,
|
||||
PromptLog,
|
||||
|
|
@ -142,6 +143,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
description: string | undefined;
|
||||
},
|
||||
];
|
||||
"mcp/startAuthentication": [MCPServerStatus, void];
|
||||
"mcp/sendOauthCode": [
|
||||
{
|
||||
code: string;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"config/updateSelectedModel",
|
||||
"mcp/reloadServer",
|
||||
"mcp/getPrompt",
|
||||
"mcp/startAuthentication",
|
||||
"context/getContextItems",
|
||||
"context/getSymbolsForFiles",
|
||||
"context/loadSubmenuItems",
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
import { ConfigYaml, parseConfigYaml } from "@continuedev/config-yaml";
|
||||
import {
|
||||
ArrowLeftCircleIcon,
|
||||
ArrowPathIcon,
|
||||
CircleStackIcon,
|
||||
CommandLineIcon,
|
||||
GlobeAltIcon,
|
||||
InformationCircleIcon,
|
||||
UserCircleIcon,
|
||||
WrenchScrewdriverIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { MCPServerStatus } from "core";
|
||||
import { useContext, useMemo } from "react";
|
||||
import { useContext, useMemo, useState } from "react";
|
||||
import { useAuth } from "../../../../../context/Auth";
|
||||
import { IdeMessengerContext } from "../../../../../context/IdeMessenger";
|
||||
import { useAppDispatch, useAppSelector } from "../../../../../redux/hooks";
|
||||
|
|
@ -17,6 +20,10 @@ import { ToolTip } from "../../../../gui/Tooltip";
|
|||
import EditBlockButton from "../../EditBlockButton";
|
||||
import { ExploreBlocksButton } from "../ExploreBlocksButton";
|
||||
|
||||
function has401Error(errors: string[]) {
|
||||
return !!errors.find((error) => error.includes("401"));
|
||||
}
|
||||
|
||||
interface MCPServerStatusProps {
|
||||
server: MCPServerStatus;
|
||||
serverFromYaml?: NonNullable<ConfigYaml["mcpServers"]>[number];
|
||||
|
|
@ -30,7 +37,17 @@ function MCPServerPreview({ server, serverFromYaml }: MCPServerStatusProps) {
|
|||
const resourcesTooltipId = `${server.id}-resources`;
|
||||
const errorsTooltipId = `${server.id}-errors`;
|
||||
|
||||
async function onRefresh() {
|
||||
const [mcpAuthStatus, setMcpAuthStatus] = useState<
|
||||
"unauthenticated" | "authenticated" | "authenticating"
|
||||
>("unauthenticated");
|
||||
|
||||
const onAuthenticate = async () => {
|
||||
setMcpAuthStatus("authenticating"); // TODO: move this updateConfig later with "authenticated" and "authenticating" status
|
||||
await ideMessenger.request("mcp/startAuthentication", server);
|
||||
setMcpAuthStatus("authenticated");
|
||||
};
|
||||
|
||||
const onRefresh = async () => {
|
||||
// optimistic config update
|
||||
dispatch(
|
||||
updateConfig({
|
||||
|
|
@ -48,7 +65,13 @@ function MCPServerPreview({ server, serverFromYaml }: MCPServerStatusProps) {
|
|||
ideMessenger.post("mcp/reloadServer", {
|
||||
id: server.id,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// useEffect(() => {
|
||||
// if (hasConnectionResetError(server.errors)) {
|
||||
// onRefresh();
|
||||
// }
|
||||
// }, [server.errors]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
@ -130,8 +153,23 @@ function MCPServerPreview({ server, serverFromYaml }: MCPServerStatusProps) {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{/* Refresh button */}
|
||||
<div className="flex items-center gap-2">
|
||||
{has401Error(server.errors) && (
|
||||
<>
|
||||
<div
|
||||
className="text-lightgray flex cursor-pointer items-center hover:opacity-80"
|
||||
onClick={onAuthenticate}
|
||||
>
|
||||
{mcpAuthStatus === "authenticating" ? (
|
||||
<GlobeAltIcon className="h-3 w-3" />
|
||||
) : mcpAuthStatus === "authenticated" ? (
|
||||
<ArrowLeftCircleIcon className="h-3 w-3" />
|
||||
) : (
|
||||
<UserCircleIcon className="h-3 w-3" />
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<EditBlockButton
|
||||
blockType={"mcpServers"}
|
||||
block={serverFromYaml}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue