/**
* LinkedIn View My Profile Tool
*/
import { z } from "zod";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { getClient } from "../api/client.js";
// Input Schema
const InputSchema = z.object({
session_id: z.string().describe("Session ID from linkedin_auth"),
}).strict();
// Output Schema
const ExperienceSchema = z.object({
title: z.string().describe("Job title"),
company: z.string().describe("Company name"),
location: z.string().describe("Location"),
description: z.string().describe("Job description"),
});
const EducationSchema = z.object({
school: z.string().describe("School name"),
degree: z.string().describe("Degree name"),
field: z.string().describe("Field of study"),
});
const CertificationSchema = z.object({
name: z.string().describe("Certification name"),
issuer: z.string().describe("Issuing organization"),
});
const OutputSchema = z.object({
name: z.string().describe("Your full name"),
headline: z.string().describe("Your professional headline"),
summary: z.string().describe("Your about/summary section"),
profileUrl: z.string().describe("Your LinkedIn profile URL"),
publicId: z.string().describe("Your public identifier/username"),
experience: z.array(ExperienceSchema).describe("Your work experience"),
education: z.array(EducationSchema).describe("Your education history"),
skills: z.array(z.string()).describe("Your skills list"),
certifications: z.array(CertificationSchema).describe("Your certifications"),
}).strict();
const DESCRIPTION = `View the logged-in user's own LinkedIn profile.
**Requires session_id from linkedin_auth**
Returns: Your name, headline, about, experience, education, certifications, skills`;
export function registerViewMyProfileTool(server: McpServer): void {
server.registerTool(
"view_my_profile",
{
title: "View My Profile",
description: DESCRIPTION,
inputSchema: InputSchema,
outputSchema: OutputSchema,
annotations: {
title: "View My LinkedIn Profile",
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: false,
},
},
async (args) => {
try {
const client = getClient(args.session_id);
const profile = await client.getMyProfile();
let output = `# ${profile.name}\n\n**${profile.headline}**\n\n`;
if (profile.summary) output += `## About\n${profile.summary}\n\n`;
output += `| Field | Value |\n|-------|-------|\n`;
output += `| Name | ${profile.name} |\n`;
output += `| Headline | ${profile.headline} |\n`;
output += `| Profile | ${profile.profileUrl} |\n\n`;
if (profile.experience.length > 0) {
output += `## Experience (${profile.experience.length})\n`;
for (const exp of profile.experience) {
output += `- **${exp.title}** @ ${exp.company}\n`;
if (exp.location) output += ` 📍 ${exp.location}\n`;
if (exp.description) output += ` ${exp.description.substring(0, 200)}...\n`;
}
output += "\n";
}
if (profile.education.length > 0) {
output += `## Education (${profile.education.length})\n`;
for (const edu of profile.education) {
output += `- **${edu.school}** - ${edu.degree}${edu.field ? `, ${edu.field}` : ""}\n`;
}
output += "\n";
}
if (profile.skills.length > 0) {
output += `## Skills (${profile.skills.length})\n${profile.skills.slice(0, 15).join(", ")}\n\n`;
}
if (profile.certifications.length > 0) {
output += `## Certifications (${profile.certifications.length})\n`;
for (const cert of profile.certifications) {
output += `- **${cert.name}** by ${cert.issuer}\n`;
}
}
return {
content: [{ type: "text" as const, text: output }],
structuredContent: {
name: profile.name,
headline: profile.headline,
summary: profile.summary,
profileUrl: profile.profileUrl,
publicId: profile.publicId,
experience: profile.experience,
education: profile.education,
skills: profile.skills,
certifications: profile.certifications,
},
};
} catch (error) {
return {
content: [{ type: "text" as const, text: `Error: ${error instanceof Error ? error.message : String(error)}` }],
isError: true,
};
}
}
);
}