Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

feat: Add Queston mcp tool

Khuram Niaz6ca96aecbf88
diff --git a/__tests__/AiJobMatchSection.spec.tsx b/__tests__/AiJobMatchSection.spec.tsx
index 0fc0c6f..949e92b 100644
--- a/__tests__/AiJobMatchSection.spec.tsx
+++ b/__tests__/AiJobMatchSection.spec.tsx
@@ -62,6 +62,7 @@ vi.mock("@/components/ui/sheet", () => ({
SheetContent: ({ children }: any) => <div>{children}</div>,
SheetHeader: ({ children }: any) => <div>{children}</div>,
SheetTitle: ({ children }: any) => <div>{children}</div>,
+ SheetClose: ({ children }: any) => <div>{children}</div>,
}));
vi.mock("@/components/ui/tooltip", () => ({
diff --git a/__tests__/AiResumeReviewSection.spec.tsx b/__tests__/AiResumeReviewSection.spec.tsx
index d6181d4..cefef9f 100644
--- a/__tests__/AiResumeReviewSection.spec.tsx
+++ b/__tests__/AiResumeReviewSection.spec.tsx
@@ -59,6 +59,7 @@ vi.mock("@/components/ui/sheet", () => ({
),
SheetHeader: ({ children }: any) => <div>{children}</div>,
SheetTitle: ({ children }: any) => <div>{children}</div>,
+ SheetClose: ({ children }: any) => <div>{children}</div>,
SheetTrigger: ({ children }: any) => (
<div data-testid="sheet-trigger">{children}</div>
),
diff --git a/__tests__/JobDetails.spec.tsx b/__tests__/JobDetails.spec.tsx
index 6c5f79f..730d854 100644
--- a/__tests__/JobDetails.spec.tsx
+++ b/__tests__/JobDetails.spec.tsx
@@ -32,6 +32,12 @@ vi.mock("@/components/profile/DownloadFileButton", () => ({
DownloadFileButton: () => null,
}));
+vi.mock("@/components/CircularScore", () => ({
+ CircularScore: ({ score }: { score: number }) => (
+ <div data-testid="circular-score">{score}%</div>
+ ),
+}));
+
const makeJob = (overrides: Partial<JobResponse> = {}): JobResponse => ({
id: "job-1",
userId: "user-1",
@@ -138,7 +144,7 @@ describe("JobDetails – match data display", () => {
render(<JobDetails job={makeJob({ matchScore: 85, matchData })} />);
expect(screen.getByText("AI Match Analysis")).toBeInTheDocument();
- expect(screen.getByText("85% Match")).toBeInTheDocument();
+ expect(screen.getByText("85%")).toBeInTheDocument();
expect(screen.getByTestId("match-details")).toBeInTheDocument();
});
@@ -166,7 +172,7 @@ describe("JobDetails – match data display", () => {
});
expect(screen.getByText("AI Match Analysis")).toBeInTheDocument();
- expect(screen.getByText("72% Match")).toBeInTheDocument();
+ expect(screen.getByText("72%")).toBeInTheDocument();
expect(screen.getByTestId("match-details")).toBeInTheDocument();
});
@@ -177,7 +183,7 @@ describe("JobDetails – match data display", () => {
});
render(<JobDetails job={makeJob({ matchScore: 60, matchData: oldMatchData })} />);
- expect(screen.getByText("60% Match")).toBeInTheDocument();
+ expect(screen.getByText("60%")).toBeInTheDocument();
const newMatchData = JSON.stringify({
matchScore: 90,
@@ -188,7 +194,7 @@ describe("JobDetails – match data display", () => {
capturedOnMatchSaved?.(90, newMatchData);
});
- expect(screen.queryByText("60% Match")).not.toBeInTheDocument();
- expect(screen.getByText("90% Match")).toBeInTheDocument();
+ expect(screen.queryByText("60%")).not.toBeInTheDocument();
+ expect(screen.getByText("90%")).toBeInTheDocument();
});
});
diff --git a/__tests__/addQuestionForm.schema.spec.ts b/__tests__/addQuestionForm.schema.spec.ts
index d8a8876..a73adf7 100644
--- a/__tests__/addQuestionForm.schema.spec.ts
+++ b/__tests__/addQuestionForm.schema.spec.ts
@@ -14,64 +14,90 @@ describe("AddQuestionFormSchema", () => {
expect(result.tagIds).toEqual(["tag-1", "tag-2"]);
});
- it("should accept question without answer", () => {
- const data = { question: "What is React?" };
- const result = AddQuestionFormSchema.parse(data);
- expect(result.question).toBe("What is React?");
- expect(result.answer).toBeUndefined();
- });
-
- it("should accept null answer", () => {
- const data = { question: "What is React?", answer: null };
- const result = AddQuestionFormSchema.parse(data);
- expect(result.answer).toBeNull();
- });
-
it("should accept question without tagIds", () => {
- const data = { question: "What is React?" };
+ const data = {
+ question: "What is React?",
+ answer: "A JavaScript library for building UIs.",
+ };
const result = AddQuestionFormSchema.parse(data);
expect(result.tagIds).toBeUndefined();
});
it("should accept empty tagIds array", () => {
- const data = { question: "What is React?", tagIds: [] };
+ const data = {
+ question: "What is React?",
+ answer: "A JavaScript library for building UIs.",
+ tagIds: [],
+ };
const result = AddQuestionFormSchema.parse(data);
expect(result.tagIds).toEqual([]);
});
it("should accept optional id for editing", () => {
- const data = { id: "q-123", question: "Updated question?" };
+ const data = {
+ id: "q-123",
+ question: "Updated question?",
+ answer: "A JavaScript library for building UIs.",
+ };
const result = AddQuestionFormSchema.parse(data);
expect(result.id).toBe("q-123");
});
- it("should accept minimum length question (2 chars)", () => {
- const data = { question: "ab" };
+ it("should accept minimum length question (5 chars)", () => {
+ const data = {
+ question: "abcde",
+ answer: "A JavaScript library for building UIs.",
+ };
+ const result = AddQuestionFormSchema.parse(data);
+ expect(result.question).toBe("abcde");
+ });
+
+ it("should accept minimum length answer (10 chars)", () => {
+ const data = { question: "What is React?", answer: "1234567890" };
const result = AddQuestionFormSchema.parse(data);
- expect(result.question).toBe("ab");
+ expect(result.answer).toBe("1234567890");
});
it("should accept up to 10 tags", () => {
const tagIds = Array.from({ length: 10 }, (_, i) => `tag-${i}`);
- const data = { question: "What is React?", tagIds };
+ const data = {
+ question: "What is React?",
+ answer: "A JavaScript library for building UIs.",
+ tagIds,
+ };
const result = AddQuestionFormSchema.parse(data);
expect(result.tagIds).toHaveLength(10);
});
});
describe("invalid data", () => {
- it("should reject question shorter than 2 characters", () => {
- const data = { question: "a" };
+ it("should reject question shorter than 5 characters", () => {
+ const data = { question: "ab", answer: "1234567890" };
expect(() => AddQuestionFormSchema.parse(data)).toThrow();
});
it("should reject empty question", () => {
- const data = { question: "" };
+ const data = { question: "", answer: "1234567890" };
expect(() => AddQuestionFormSchema.parse(data)).toThrow();
});
it("should reject missing question", () => {
- const data = { answer: "Some answer" };
+ const data = { answer: "1234567890" };
+ expect(() => AddQuestionFormSchema.parse(data)).toThrow();
+ });
+
+ it("should reject missing answer", () => {
+ const data = { question: "What is React?" };
+ expect(() => AddQuestionFormSchema.parse(data)).toThrow();
+ });
+
+ it("should reject null answer", () => {
+ const data = { question: "What is React?", answer: null };
+ expect(() => AddQuestionFormSchema.parse(data)).toThrow();
+ });
+
+ it("should reject answer shorter than 10 characters", () => {
+ const data = { question: "What is React?", answer: "short" };
expect(() => AddQuestionFormSchema.parse(data)).toThrow();
});
@@ -82,7 +108,7 @@ describe("AddQuestionFormSchema", () => {
it("should reject more than 10 tags", () => {
const tagIds = Array.from({ length: 11 }, (_, i) => `tag-${i}`);
- const data = { question: "What?", tagIds };
+ const data = { question: "What?", answer: "1234567890", tagIds };
expect(() => AddQuestionFormSchema.parse(data)).toThrow();
});
diff --git a/__tests__/question.actions.spec.ts b/__tests__/question.actions.spec.ts
index 88aa9a8..4ad1300 100644
--- a/__tests__/question.actions.spec.ts
+++ b/__tests__/question.actions.spec.ts
@@ -248,13 +248,14 @@ describe("Question Actions", () => {
const result = await createQuestion({
question: "What is React?",
+ answer: "<p>A JS library</p>",
});
expect(result?.success).toBe(true);
expect(prisma.question.create).toHaveBeenCalledWith({
data: {
question: "What is React?",
- answer: null,
+ answer: "<p>A JS library</p>",
createdBy: mockUser.id,
tags: undefined,
},
@@ -262,23 +263,34 @@ describe("Question Actions", () => {
});
});
- it("should create a question with null answer", async () => {
+ it("should reject invalid data (null answer)", async () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
- (prisma.question.create as any).mockResolvedValue(mockQuestion);
- await createQuestion({ question: "What?", answer: null });
+ const result = await createQuestion({ question: "What?", answer: null } as any);
- expect(prisma.question.create).toHaveBeenCalledWith(
- expect.objectContaining({
- data: expect.objectContaining({ answer: null }),
- }),
- );
+ expect(result?.success).toBe(false);
+ expect(prisma.question.create).not.toHaveBeenCalled();
});
it("should reject invalid data (question too short)", async () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
- const result = await createQuestion({ question: "a" });
+ const result = await createQuestion({
+ question: "a",
+ answer: "<p>A JS library</p>",
+ });
+
+ expect(result?.success).toBe(false);
+ expect(prisma.question.create).not.toHaveBeenCalled();
+ });
+
+ it("should reject invalid data (answer too short)", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+
+ const result = await createQuestion({
+ question: "What is React?",
+ answer: "short",
+ });
expect(result?.success).toBe(false);
expect(prisma.question.create).not.toHaveBeenCalled();
@@ -287,7 +299,10 @@ describe("Question Actions", () => {
it("should return error for unauthenticated user", async () => {
(getCurrentUser as any).mockResolvedValue(null);
- const result = await createQuestion({ question: "What is React?" });
+ const result = await createQuestion({
+ question: "What is React?",
+ answer: "<p>A JS library</p>",
+ });
expect(result).toEqual({
success: false,
@@ -302,7 +317,10 @@ describe("Question Actions", () => {
new Error("DB error"),
);
- const result = await createQuestion({ question: "What is React?" });
+ const result = await createQuestion({
+ question: "What is React?",
+ answer: "<p>A JS library</p>",
+ });
expect(result).toEqual({ success: false, message: "DB error" });
});
@@ -340,6 +358,7 @@ describe("Question Actions", () => {
await updateQuestion({
id: "q-1",
question: "Updated?",
+ answer: "<p>Updated answer</p>",
tagIds: [],
});
@@ -355,7 +374,10 @@ describe("Question Actions", () => {
it("should return error when id is missing", async () => {
(getCurrentUser as any).mockResolvedValue(mockUser);
- const result = await updateQuestion({ question: "No ID?" });
+ const result = await updateQuestion({
+ question: "No ID?",
+ answer: "<p>Updated answer</p>",
+ });
expect(result?.success).toBe(false);
expect(prisma.question.update).not.toHaveBeenCalled();
@@ -367,6 +389,7 @@ describe("Question Actions", () => {
const result = await updateQuestion({
id: "q-1",
question: "Updated?",
+ answer: "<p>Updated answer</p>",
});
expect(result).toEqual({
@@ -385,6 +408,7 @@ describe("Question Actions", () => {
const result = await updateQuestion({
id: "q-1",
question: "Updated?",
+ answer: "<p>Updated answer</p>",
});
expect(result).toEqual({ success: false, message: "DB error" });
diff --git a/prisma/migrations/20260701071535_add_question_created_via/migration.sql b/prisma/migrations/20260701071535_add_question_created_via/migration.sql
new file mode 100644
index 0000000..dc3612c
--- /dev/null
+++ b/prisma/migrations/20260701071535_add_question_created_via/migration.sql
@@ -0,0 +1,6 @@
+-- AlterTable
+ALTER TABLE "Question" ADD COLUMN "createdVia" TEXT;
+
+-- Backfill: grant questions:write to all existing tokens (all currently ["jobs:write"])
+UPDATE "McpAccessToken" SET scopes = '["jobs:write","questions:write"]'
+WHERE scopes = '["jobs:write"]';
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 4a82510..9815fba 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -479,14 +479,15 @@ model Skill {
}
model Question {
- id String @id @default(uuid())
- question String
- answer String?
- createdBy String
- user User @relation(fields: [createdBy], references: [id])
- tags Tag[]
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
+ id String @id @default(uuid())
+ question String
+ answer String?
+ createdBy String
+ user User @relation(fields: [createdBy], references: [id])
+ tags Tag[]
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ createdVia String? // MCP provenance: which agent/token created this, mirrors Job.createdVia
@@index([createdBy])
}
@@ -498,7 +499,7 @@ model McpAccessToken {
name String
tokenHash String @unique
tokenPrefix String
- scopes String // JSON array string; v1 always ["jobs:write"]
+ scopes String // JSON array string; new tokens are always ["jobs:write","questions:write"]
expiresAt DateTime
lastUsedAt DateTime?
createdAt DateTime @default(now())
diff --git a/src/actions/mcpToken.actions.ts b/src/actions/mcpToken.actions.ts
index 1467639..7dd99d6 100644
--- a/src/actions/mcpToken.actions.ts
+++ b/src/actions/mcpToken.actions.ts
@@ -44,7 +44,7 @@ export async function createMcpToken(input: {
name: input.name.trim(),
tokenHash: hash,
tokenPrefix: prefix,
- scopes: JSON.stringify(["jobs:write"]),
+ scopes: JSON.stringify(["jobs:write", "questions:write"]),
expiresAt,
},
});
diff --git a/src/app/api/mcp/route.ts b/src/app/api/mcp/route.ts
index d0a200a..ff6c5fa 100644
--- a/src/app/api/mcp/route.ts
+++ b/src/app/api/mcp/route.ts
@@ -1,8 +1,14 @@
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
import { resolveMcpToken } from "@/lib/mcp/auth";
-import { McpAddJobInputShape, McpAddJobSchema } from "@/models/mcp.schema";
+import {
+ McpAddJobInputShape,
+ McpAddJobSchema,
+ McpAddQuestionInputShape,
+ McpAddQuestionSchema,
+} from "@/models/mcp.schema";
import { handleAddJob } from "@/lib/mcp/tools/addJob";
+import { handleAddQuestion } from "@/lib/mcp/tools/addQuestion";
function isMcpEnabled(): boolean {
const env = process.env.MCP_ENABLED;
@@ -25,13 +31,6 @@ async function handler(req: Request): Promise<Response> {
});
}
- if (!auth.scopes.includes("jobs:write")) {
- return new Response(JSON.stringify({ error: "Insufficient scope. Required: jobs:write" }), {
- status: 403,
- headers: { "Content-Type": "application/json" },
- });
- }
-
const { userId, tokenName } = auth;
const server = new McpServer({ name: "jobsync", version: "1.0.0" });
@@ -41,6 +40,9 @@ async function handler(req: Request): Promise<Response> {
"Add a job application to JobSync. Resolves or creates company, job title, location, and source by name. Returns a transparency report of what was matched vs. created.",
McpAddJobInputShape,
async (rawInput) => {
+ if (!auth.scopes.includes("jobs:write")) {
+ return { content: [{ type: "text" as const, text: "Insufficient scope. Required: jobs:write" }] };
+ }
const parsed = McpAddJobSchema.safeParse(rawInput);
if (!parsed.success) {
const issues = parsed.error.issues.map((i) => i.message).join("; ");
@@ -50,6 +52,23 @@ async function handler(req: Request): Promise<Response> {
},
);
+ server.tool(
+ "add_question",
+ "Add an entry to the Question Bank. Resolves or creates tags by name. Returns a transparency report of what was matched vs. created.",
+ McpAddQuestionInputShape,
+ async (rawInput) => {
+ if (!auth.scopes.includes("questions:write")) {
+ return { content: [{ type: "text" as const, text: "Insufficient scope. Required: questions:write" }] };
+ }
+ const parsed = McpAddQuestionSchema.safeParse(rawInput);
+ if (!parsed.success) {
+ const issues = parsed.error.issues.map((i) => i.message).join("; ");
+ return { content: [{ type: "text" as const, text: `Validation error: ${issues}` }] };
+ }
+ return handleAddQuestion(parsed.data, userId, tokenName);
+ },
+ );
+
const transport = new WebStandardStreamableHTTPServerTransport({
sessionIdGenerator: undefined, // stateless mode
enableJsonResponse: true, // return plain JSON instead of SSE stream
diff --git a/src/components/questions/QuestionCard.tsx b/src/components/questions/QuestionCard.tsx
index d8f19fb..207aefa 100644
--- a/src/components/questions/QuestionCard.tsx
+++ b/src/components/questions/QuestionCard.tsx
@@ -109,6 +109,14 @@ export function QuestionCard({
</div>
)}
+ {question.createdVia && (
+ <div className="mt-2">
+ <Badge variant="outline" className="text-xs text-muted-foreground">
+ via {question.createdVia}
+ </Badge>
+ </div>
+ )}
+
{isLongAnswer && (
<button
className="text-xs text-primary mt-2 hover:underline"
diff --git a/src/components/questions/QuestionForm.tsx b/src/components/questions/QuestionForm.tsx
index 42fcb28..58b0be1 100644
--- a/src/components/questions/QuestionForm.tsx
+++ b/src/components/questions/QuestionForm.tsx
@@ -158,7 +158,7 @@ export function QuestionForm({
name="answer"
render={({ field }) => (
<FormItem className="flex flex-col">
- <FormLabel>Answer</FormLabel>
+ <FormLabel>Answer *</FormLabel>
<FormControl>
<TiptapEditor field={field} />
</FormControl>
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index ce345b1..4844bb5 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -14,6 +14,10 @@ export const APP_CONSTANTS = {
RECORDS_PER_PAGE: 25,
MAX_AUTOMATIONS_PER_USER: 10,
MAX_JOB_TAGS: 10,
+ MIN_QUESTION_LENGTH: 5,
+ MAX_QUESTION_LENGTH: 500,
+ MIN_QUESTION_ANSWER_LENGTH: 10,
+ MAX_QUESTION_ANSWER_LENGTH: 5000,
MAX_SKILL_CATEGORIES: 8,
MAX_SKILLS_PER_CATEGORY: 20,
ACTIVITY_MAX_DURATION_MINUTES: 8 * 60, // 8 Hours
diff --git a/src/lib/mcp/tools/addQuestion.ts b/src/lib/mcp/tools/addQuestion.ts
new file mode 100644
index 0000000..c010913
--- /dev/null
+++ b/src/lib/mcp/tools/addQuestion.ts
@@ -0,0 +1,37 @@
+import { z } from "zod";
+import { McpAddQuestionSchema } from "@/models/mcp.schema";
+import { createQuestionFromNames } from "@/lib/questions/createQuestionFromNames";
+import { checkMcpRateLimit } from "@/lib/mcp/rate-limit";
+
+export const addQuestionToolDefinition = {
+ name: "add_question",
+ description:
+ "Add an entry to the Question Bank. Resolves or creates tags by name. Returns a transparency report of what was matched vs. created.",
+ inputSchema: McpAddQuestionSchema,
+} as const;
+
+export async function handleAddQuestion(
+ input: z.infer<typeof McpAddQuestionSchema>,
+ userId: string,
+ tokenName: string,
+): Promise<{ content: Array<{ type: "text"; text: string }> }> {
+ const rateCheck = checkMcpRateLimit(userId);
+ if (!rateCheck.allowed) {
+ const resetSec = Math.ceil(rateCheck.resetIn / 1000);
+ return {
+ content: [{ type: "text", text: `Rate limit exceeded. Try again in ${resetSec}s.` }],
+ };
+ }
+
+ try {
+ const result = await createQuestionFromNames(
+ { ...input, createdVia: tokenName },
+ userId,
+ );
+ return { content: [{ type: "text", text: result.message }] };
+ } catch (err: any) {
+ return {
+ content: [{ type: "text", text: `Error: ${err?.message ?? "Unknown error"}` }],
+ };
+ }
+}
diff --git a/src/lib/questions/createQuestionFromNames.ts b/src/lib/questions/createQuestionFromNames.ts
new file mode 100644
index 0000000..e8df68f
--- /dev/null
+++ b/src/lib/questions/createQuestionFromNames.ts
@@ -0,0 +1,68 @@
+import MarkdownIt from "markdown-it";
+import prisma from "@/lib/db";
+import { APP_CONSTANTS } from "@/lib/constants";
+import { resolveTags, type ResolvedEntity } from "@/lib/jobs/resolve";
+
+// html:false escapes any raw HTML in the input; TipTapContentViewer further
+// strips unrecognized tags, so the stored/rendered answer is safe.
+const md = new MarkdownIt({ html: false, linkify: false, breaks: true });
+
+export interface CreateQuestionFromNamesInput {
+ question: string;
+ answer: string;
+ tags?: string[];
+ createdVia?: string;
+}
+
+export interface CreateQuestionFromNamesResult {
+ questionId: string;
+ resolutions: ResolvedEntity[];
+ message: string;
+}
+
+export async function createQuestionFromNames(
+ input: CreateQuestionFromNamesInput,
+ userId: string,
+): Promise<CreateQuestionFromNamesResult> {
+ const { question, answer, tags = [], createdVia } = input;
+
+ const resolvedTagsResult = await resolveTags(tags, userId, APP_CONSTANTS.MAX_JOB_TAGS);
+ const resolutions: ResolvedEntity[] = resolvedTagsResult.resolved;
+
+ const html = md.render(answer);
+
+ const created = await prisma.question.create({
+ data: {
+ question,
+ answer: html,
+ createdBy: userId,
+ createdVia: createdVia ?? null,
+ tags: { connect: resolvedTagsResult.resolved.map((t) => ({ id: t.id })) },
+ },
+ });
+
+ const message = buildSuccessMessage(resolutions, resolvedTagsResult.dropped, created.id);
+
+ return {
+ questionId: created.id,
+ resolutions,
+ message,
+ };
+}
+
+function buildSuccessMessage(
+ resolutions: ResolvedEntity[],
+ droppedTags: string[],
+ questionId: string,
+): string {
+ const parts = resolutions.map((r) => {
+ const action = r.created ? "Created" : "Matched";
+ return `${action} ${r.label}`;
+ });
+ let msg = parts.length > 0 ? parts.join("; ") + ". " : "";
+ msg += `Question created (id: ${questionId}).`;
+ if (droppedTags.length > 0) {
+ msg += ` Dropped tags exceeding limit: ${droppedTags.join(", ")}.`;
+ }
+ return msg;
+}
diff --git a/src/models/addQuestionForm.schema.ts b/src/models/addQuestionForm.schema.ts
index ae0e1f0..cbce834 100644
--- a/src/models/addQuestionForm.schema.ts
+++ b/src/models/addQuestionForm.schema.ts
@@ -5,12 +5,12 @@ export const AddQuestionFormSchema = z.object({
id: z.string().optional(),
question: z
.string({ error: "Question is required." })
- .min(2, { message: "Question must be at least 2 characters." }),
+ .min(APP_CONSTANTS.MIN_QUESTION_LENGTH, { message: `Question must be at least ${APP_CONSTANTS.MIN_QUESTION_LENGTH} characters.` })
+ .max(APP_CONSTANTS.MAX_QUESTION_LENGTH, { message: `Question cannot exceed ${APP_CONSTANTS.MAX_QUESTION_LENGTH} characters.` }),
answer: z
- .string()
- .max(5000, { message: "Answer cannot exceed 5000 characters." })
- .optional()
- .nullable(),
+ .string({ error: "Answer is required." })
+ .min(APP_CONSTANTS.MIN_QUESTION_ANSWER_LENGTH, { message: `Answer must be at least ${APP_CONSTANTS.MIN_QUESTION_ANSWER_LENGTH} characters.` })
+ .max(APP_CONSTANTS.MAX_QUESTION_ANSWER_LENGTH, { message: `Answer cannot exceed ${APP_CONSTANTS.MAX_QUESTION_ANSWER_LENGTH} characters.` }),
tagIds: z
.array(z.string())
.max(APP_CONSTANTS.MAX_JOB_TAGS, { message: `Maximum ${APP_CONSTANTS.MAX_JOB_TAGS} skill tags allowed.` })
diff --git a/src/models/mcp.schema.ts b/src/models/mcp.schema.ts
index 0e2d577..0aef51b 100644
--- a/src/models/mcp.schema.ts
+++ b/src/models/mcp.schema.ts
@@ -1,4 +1,5 @@
import { z } from "zod";
+import { APP_CONSTANTS } from "@/lib/constants";
// Raw input shape for MCP tool registration (no transforms — SDK uses this for JSON schema)
export const McpAddJobInputShape = {
@@ -26,3 +27,19 @@ export const McpAddJobSchema = z.object({
});
export type McpAddJobInput = z.infer<typeof McpAddJobSchema>;
+
+// Raw input shape for MCP tool registration (no transforms — SDK uses this for JSON schema)
+export const McpAddQuestionInputShape = {
+ question: z.string()
+ .min(APP_CONSTANTS.MIN_QUESTION_LENGTH, `question must be at least ${APP_CONSTANTS.MIN_QUESTION_LENGTH} characters`)
+ .max(APP_CONSTANTS.MAX_QUESTION_LENGTH, `question cannot exceed ${APP_CONSTANTS.MAX_QUESTION_LENGTH} characters`),
+ answer: z.string()
+ .min(APP_CONSTANTS.MIN_QUESTION_ANSWER_LENGTH, `answer must be at least ${APP_CONSTANTS.MIN_QUESTION_ANSWER_LENGTH} characters`)
+ .max(APP_CONSTANTS.MAX_QUESTION_ANSWER_LENGTH, `answer cannot exceed ${APP_CONSTANTS.MAX_QUESTION_ANSWER_LENGTH} characters`)
+ .describe("Markdown-formatted answer/notes (required). Plain text also works."),
+ tags: z.array(z.string()).optional()
+ .describe("Skill/topic tags (max 10 applied, extras dropped). Created if they don't exist."),
+};
+
+export const McpAddQuestionSchema = z.object(McpAddQuestionInputShape);
+export type McpAddQuestionInput = z.infer<typeof McpAddQuestionSchema>;
diff --git a/src/models/question.model.ts b/src/models/question.model.ts
index 00a18d2..fd2b75f 100644
--- a/src/models/question.model.ts
+++ b/src/models/question.model.ts
@@ -8,4 +8,5 @@ export interface Question {
tags: Tag[];
createdAt: Date;
updatedAt: Date;
+ createdVia?: string | null;
}
diff --git a/vitest.setup.ts b/vitest.setup.ts
index 90e5de0..7b3c417 100644
--- a/vitest.setup.ts
+++ b/vitest.setup.ts
@@ -10,3 +10,9 @@ global.ResizeObserver = class ResizeObserver {
unobserve() {}
disconnect() {}
};
+
+global.IntersectionObserver = class IntersectionObserver {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+} as unknown as typeof IntersectionObserver;