Skip to main content
Glama

affine_sign_in

Authenticate users by signing into AFFiNE with email and password; generates session cookies for continuous access to workspace operations, including document management and search.

Instructions

Sign in to AFFiNE using email and password; sets session cookies for subsequent calls.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
emailYes
passwordYes

Implementation Reference

  • Handler function for the affine_sign_in tool that invokes loginWithPassword, sets the session cookie on the GraphQL client, and returns a success text response.
    const signInHandler = async (parsed: { email: string; password: string }) => {
      const { cookieHeader } = await loginWithPassword(baseUrl, parsed.email, parsed.password);
      gql.setCookie(cookieHeader);
      return text({ signedIn: true });
    };
  • Input schema using Zod: email must be a valid email string, password must be a non-empty string.
    inputSchema: {
      email: z.string().email(),
      password: z.string().min(1)
    }
  • Registers the 'affine_sign_in' tool with the MCP server, including title, description, input schema, and the signInHandler.
    server.registerTool(
      "affine_sign_in",
      {
        title: "Sign In",
        description: "Sign in to AFFiNE using email and password; sets session cookies for subsequent calls.",
        inputSchema: {
          email: z.string().email(),
          password: z.string().min(1)
        }
      },
      signInHandler as any
    );
  • Core authentication helper that sends POST request to /api/auth/sign-in with email and password, handles response, extracts and formats Set-Cookie headers into a cookie header string.
    export async function loginWithPassword(baseUrl: string, email: string, password: string): Promise<{ cookieHeader: string }> {
      const url = `${baseUrl.replace(/\/$/, "")}/api/auth/sign-in`;
      const res = await fetch(url, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ email, password })
      });
      if (!res.ok) {
        const text = await res.text().catch(() => "");
        throw new Error(`Sign-in failed: ${res.status} ${text}`);
      }
      const anyHeaders = res.headers as any;
      let setCookies: string[] = [];
      if (typeof anyHeaders.getSetCookie === "function") {
        setCookies = anyHeaders.getSetCookie();
      } else {
        const sc = res.headers.get("set-cookie");
        if (sc) setCookies = [sc];
      }
      if (!setCookies.length) {
        throw new Error("Sign-in succeeded but no Set-Cookie received");
      }
      const cookieHeader = extractCookiePairs(setCookies);
      return { cookieHeader };
    }
  • Utility function to extract cookie name=value pairs from Set-Cookie headers, discarding attributes after semicolon.
    function extractCookiePairs(setCookies: string[]): string {
      const pairs: string[] = [];
      for (const sc of setCookies) {
        const first = sc.split(";")[0];
        if (first) pairs.push(first.trim());
      }
      return pairs.join("; ");
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DAWNCR0W/affine-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server