Skip to content

Feat/add user update #2

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
merged 1 commit into from
Mar 31, 2025
Merged
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
3 changes: 1 addition & 2 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ jobs:

# Setup .npmrc file to publish to npm
- name: Setup the node
uses: actions/setup-node@v4
uses: actions/setup-node@v4.3.0
with:
node-version: '22.13.14'
registry-url: 'https://registry.npmjs.org'

- name: Publish mcp-server-edgee on npm
Expand Down
11 changes: 11 additions & 0 deletions src/api/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { makeEdgeeApiRequest } from './client.js';
import {
UserWithRoles,
UserUpdateInput,
Invitation,
InvitationListResponse,
InvitationCreateInput,
Expand All @@ -26,6 +27,16 @@ export async function getUser(id: string): Promise<UserWithRoles> {
return makeEdgeeApiRequest<UserWithRoles>(`/v1/users/${id}`);
}

/**
* Update a user by ID
*/
export async function updateUser(id: string, input: UserUpdateInput): Promise<UserWithRoles> {
return makeEdgeeApiRequest<UserWithRoles>(`/v1/users/${id}`, {
method: 'POST',
body: input,
});
}

// Invitation API

/**
Expand Down
70 changes: 70 additions & 0 deletions src/tools/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,76 @@ export function registerUserTools(server: McpServer): void {
}
);

// Update User
server.tool(
'edgee-updateUser',
'Update a user by ID.',
{
id: z.string(),
avatar_url: z.string().optional(),
terms_version: z.string().optional(),
privacy_version: z.string().optional(),
},
async ({ id, avatar_url, terms_version, privacy_version }) => {
try {
const user = await api.updateUser(id, {
avatar_url,
terms_version,
privacy_version,
});

if (!user) {
return {
content: [
{
type: 'text',
text: `Failed to update user with ID: ${id}`,
},
],
};
}

// Format user roles
let rolesText = '';
if (user.roles && Object.keys(user.roles).length > 0) {
const formattedRoles = Object.entries(user.roles).map(([orgId, role]) => `Organization ${orgId}: ${role}`);
rolesText = `\nRoles:\n ${formattedRoles.join('\n ')}`;
}

const userText = [
`User updated successfully:`,
`Name: ${user.name || 'Unknown'}`,
`ID: ${user.id}`,
`Email: ${user.email || 'Unknown'}`,
`Avatar URL: ${user.avatar_url || 'None'}`,
`Created at: ${user.created_at || 'Unknown'}`,
`Updated at: ${user.updated_at || 'Unknown'}`,
rolesText,
].join('\n');

return {
content: [
{
type: 'text',
text: userText,
},
],
};
} catch (error) {
console.error('Error in edgee-updateUser:', error);
return {
content: [
{
type: 'text',
text: `Error updating user: ${error instanceof Error ? error.message : String(error)}`,
},
],
isError: true,
};
}
}
);

// List Invitations
server.tool(
'edgee-listInvitations',
Expand Down
6 changes: 6 additions & 0 deletions src/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ export interface ApiTokenCreateInput {
name: string;
expires_at?: string;
}

export interface UserUpdateInput {
avatar_url?: string;
terms_version?: string;
privacy_version?: string;
}