Repository navigation
feat: MCP tokens section in user settings #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+605
−1
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import type { Ref } from 'vue'; | ||
| import { onMounted, ref } from 'vue'; | ||
| import type { McpToken, McpTokenPermission } from '@/domain/entities/McpToken'; | ||
| import { mcpTokenService } from '@/domain'; | ||
|
|
||
| interface UseMcpTokensComposableState { | ||
| /** | ||
| * MCP tokens of the current user, newest first | ||
| */ | ||
| tokens: Ref<McpToken[]>; | ||
|
|
||
| /** | ||
| * Creates new MCP token and adds it to the list | ||
| * @param label - label set by user | ||
| * @param permission - what MCP client can do with notes | ||
| * @returns plain token, it is not available later | ||
| */ | ||
| createToken(label: string, permission: McpTokenPermission): Promise<string>; | ||
|
|
||
| /** | ||
| * Revokes MCP token and removes it from the list | ||
| * @param id - token id | ||
| */ | ||
| revokeToken(id: McpToken['id']): Promise<void>; | ||
| } | ||
|
|
||
| /** | ||
| * Methods for managing MCP tokens of the current user | ||
| */ | ||
| export default function useMcpTokens(): UseMcpTokensComposableState { | ||
| /** | ||
| * MCP tokens of the current user | ||
| */ | ||
| const tokens = ref<McpToken[]>([]); | ||
|
|
||
| /** | ||
| * Loads MCP tokens of the current user | ||
| */ | ||
| async function loadTokens(): Promise<void> { | ||
| tokens.value = await mcpTokenService.getTokens(); | ||
|
neSpecc marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Creates new MCP token and adds it to the list | ||
| * @param label - label set by user | ||
| * @param permission - what MCP client can do with notes | ||
| */ | ||
| async function createToken(label: string, permission: McpTokenPermission): Promise<string> { | ||
| const { token, item } = await mcpTokenService.createToken(label, permission); | ||
|
|
||
| tokens.value = [item, ...tokens.value]; | ||
|
|
||
| return token; | ||
| } | ||
|
|
||
| /** | ||
| * Revokes MCP token and removes it from the list | ||
| * @param id - token id | ||
| */ | ||
| async function revokeToken(id: McpToken['id']): Promise<void> { | ||
| await mcpTokenService.revokeToken(id); | ||
|
|
||
| tokens.value = tokens.value.filter(token => token.id !== id); | ||
| } | ||
|
|
||
| onMounted(async () => { | ||
| await loadTokens(); | ||
| }); | ||
|
|
||
| return { | ||
| tokens, | ||
| createToken, | ||
| revokeToken, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * What MCP client can do with notes of the token owner | ||
| */ | ||
| export type McpTokenPermission = 'read' | 'write'; | ||
|
|
||
| /** | ||
| * Personal token used by MCP clients (Claude, Cursor, etc.) to access user notes | ||
| */ | ||
| export interface McpToken { | ||
| /** | ||
| * Token id | ||
| */ | ||
| id: number; | ||
|
|
||
| /** | ||
| * Last characters of the token, used to tell tokens apart | ||
| */ | ||
| preview: string; | ||
|
|
||
| /** | ||
| * What MCP client can do with notes of the token owner | ||
| */ | ||
| permission: McpTokenPermission; | ||
|
|
||
| /** | ||
| * Label set by user, e.g. "Claude Code on laptop" | ||
| */ | ||
| label: string; | ||
|
|
||
| /** | ||
| * Last time token was used to call MCP tool | ||
| */ | ||
| lastUsedAt: string | null; | ||
|
|
||
| /** | ||
| * How many times token was used to call MCP tools | ||
| */ | ||
| requestCount: number; | ||
|
|
||
| /** | ||
| * When token was created | ||
| */ | ||
| createdAt: string; | ||
| } | ||
|
|
||
| /** | ||
| * Token returned right after creation. Plain token is shown only once | ||
| */ | ||
| export interface CreatedMcpToken { | ||
| /** | ||
| * Plain token to paste into MCP client config | ||
| */ | ||
| token: string; | ||
|
|
||
| /** | ||
| * Created token record | ||
| */ | ||
| item: McpToken; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type { CreatedMcpToken, McpToken, McpTokenPermission } from './entities/McpToken'; | ||
|
|
||
| /** | ||
| * Interface of the MCP tokens repository | ||
| */ | ||
| export default interface McpTokenRepositoryInterface { | ||
| /** | ||
| * Loads all MCP tokens of the current user | ||
| */ | ||
| getTokens(): Promise<McpToken[]>; | ||
|
|
||
| /** | ||
| * Creates new MCP token | ||
| * @param label - label set by user | ||
| * @param permission - what MCP client can do with notes | ||
| */ | ||
| createToken(label: string, permission: McpTokenPermission): Promise<CreatedMcpToken>; | ||
|
|
||
| /** | ||
| * Revokes MCP token | ||
| * @param id - token id | ||
| */ | ||
| revokeToken(id: McpToken['id']): Promise<void>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { CreatedMcpToken, McpToken, McpTokenPermission } from './entities/McpToken'; | ||
| import type McpTokenRepository from './mcpToken.repository.interface'; | ||
|
|
||
| /** | ||
| * MCP token service class, used for logic handling of the data, | ||
| * Also used for data delivery from repository to application service | ||
| */ | ||
| export default class McpTokenService { | ||
|
neSpecc marked this conversation as resolved.
Resolved
|
||
| /** | ||
| * MCP token repository instance | ||
| */ | ||
| private readonly mcpTokenRepository: McpTokenRepository; | ||
|
|
||
| constructor(mcpTokenRepository: McpTokenRepository) { | ||
| this.mcpTokenRepository = mcpTokenRepository; | ||
| } | ||
|
|
||
| /** | ||
| * Loads all MCP tokens of the current user | ||
| */ | ||
| public async getTokens(): Promise<McpToken[]> { | ||
| return await this.mcpTokenRepository.getTokens(); | ||
| } | ||
|
|
||
| /** | ||
| * Creates new MCP token | ||
| * @param label - label set by user | ||
| * @param permission - what MCP client can do with notes | ||
| */ | ||
| public async createToken(label: string, permission: McpTokenPermission): Promise<CreatedMcpToken> { | ||
| return await this.mcpTokenRepository.createToken(label, permission); | ||
| } | ||
|
|
||
| /** | ||
| * Revokes MCP token | ||
| * @param id - token id | ||
| */ | ||
| public async revokeToken(id: McpToken['id']): Promise<void> { | ||
| await this.mcpTokenRepository.revokeToken(id); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import type McpTokenRepositoryInterface from '@/domain/mcpToken.repository.interface'; | ||
| import type NotesApiTransport from './transport/notes-api'; | ||
| import type { CreatedMcpToken, McpToken, McpTokenPermission } from '@/domain/entities/McpToken'; | ||
|
|
||
| /** | ||
| * MCP tokens repository class used for data delivery from transport to service | ||
| */ | ||
| export default class McpTokenRepository implements McpTokenRepositoryInterface { | ||
| /** | ||
| * Notes api transport instance | ||
| */ | ||
| private readonly transport: NotesApiTransport; | ||
|
|
||
| constructor(notesApiTransport: NotesApiTransport) { | ||
| this.transport = notesApiTransport; | ||
| } | ||
|
|
||
| /** | ||
| * Loads all MCP tokens of the current user | ||
| */ | ||
| public async getTokens(): Promise<McpToken[]> { | ||
| const response = await this.transport.get<{ items: McpToken[] }>('/user/mcp-tokens'); | ||
|
|
||
| return response.items; | ||
| } | ||
|
|
||
| /** | ||
| * Creates new MCP token | ||
| * @param label - label set by user | ||
| * @param permission - what MCP client can do with notes | ||
| */ | ||
| public async createToken(label: string, permission: McpTokenPermission): Promise<CreatedMcpToken> { | ||
| return await this.transport.post<CreatedMcpToken>({ | ||
| endpoint: '/user/mcp-tokens', | ||
| data: { | ||
| label, | ||
| permission, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Revokes MCP token | ||
| * @param id - token id | ||
| */ | ||
| public async revokeToken(id: McpToken['id']): Promise<void> { | ||
| await this.transport.delete<{ isDeleted: boolean }>(`/user/mcp-tokens/${id}`); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.