Skip to main content
Glama
antegral
by antegral

get_drug_detail_by_id

Retrieve comprehensive pharmaceutical details using a drug code from the Korea Pharmaceutical Information Center. Access ingredients, usage instructions, precautions, and storage information for specific medications.

Instructions

약학정보원의 의약품 코드로 의약품의 상세정보를 가져옵니다. search_drugs_by_name()로 조회한 정보가 부족할 때 사용할 수 있습니다.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
drugcodeYessearch_drugs_by_name()의 결과 값에 기재된 의약품의 drug_code 값

Implementation Reference

  • Core handler function that performs the API fetch to KPIC for drug details by ID, parses the response, validates it, and returns formatted JSON string.
    export async function get_drug_detail_by_id(drugcode: string): Promise<string> {
      if (!drugcode || drugcode.trim().length === 0) {
        throw new KPICApiError('Drug code cannot be empty');
      }
    
      const now = Date.now();
      const url = `https://www.health.kr/searchDrug/ajax/ajax_result_drug2.asp?drug_cd=${encodeURIComponent(drugcode)}&_=${now}`;
    
      try {
        const response = await fetch(url, {
          method: 'GET',
          headers: {
            accept: 'application/json, text/javascript, */*; q=0.01',
            'accept-language': 'ko,en-US;q=0.9,en;q=0.8,ru;q=0.7',
            'cache-control': 'no-cache',
            pragma: 'no-cache',
            Referer: `https://www.health.kr/searchDrug/result_drug.asp?drug_cd=${encodeURIComponent(drugcode)}`,
          },
        });
    
        if (!response.ok) {
          throw new KPICApiError(`API request failed: ${response.statusText}`, response.status);
        }
    
        const data = await response.text();
    
        // 응답 데이터 검증
        try {
          const parsed = JSON.parse(data) as DrugDetailResult[];
    
          if (!Array.isArray(parsed)) {
            throw new KPICApiError('Invalid response format: expected array');
          }
    
          if (parsed.length === 0) {
            throw new KPICApiError(`No drug found with code: ${drugcode}`);
          }
    
          // 결과를 보기 좋게 포맷팅하여 반환
          return JSON.stringify(parsed, null, 2);
        } catch (parseError) {
          if (parseError instanceof KPICApiError) {
            throw parseError;
          }
          throw new KPICApiError(
            `Failed to parse API response: ${parseError instanceof Error ? parseError.message : 'Unknown error'}`,
          );
        }
      } catch (error) {
        if (error instanceof KPICApiError) {
          throw error;
        }
    
        if (error instanceof Error) {
          throw new KPICApiError(`Network error: ${error.message}`);
        }
    
        throw new KPICApiError('Unknown error occurred');
      }
  • src/index.ts:39-54 (registration)
    MCP tool registration defining the tool name, description, and input schema for get_drug_detail_by_id.
    {
      name: 'get_drug_detail_by_id',
      description:
        '약학정보원의 의약품 코드로 의약품의 상세정보를 가져옵니다. ' +
        'search_drugs_by_name()로 조회한 정보가 부족할 때 사용할 수 있습니다.',
      inputSchema: {
        type: 'object',
        properties: {
          drugcode: {
            type: 'string',
            description: 'search_drugs_by_name()의 결과 값에 기재된 의약품의 drug_code 값',
          },
        },
        required: ['drugcode'],
      },
    },
  • TypeScript interface defining the structure of the drug detail result used by the get_drug_detail_by_id handler for type safety.
     * 약품 상세 정보 타입 (get_drug_detail_by_id)
     */
    export interface DrugDetailResult {
      idx: number;
      drug_code: string;
      drug_name: string;
      drug_enm: string;
      noins: string | null;
      narcotic_kind_code: string;
      list_sunb_name: string;
      cls_code_num: string;
      sunb: string;
      drug_cls: string;
      sunb_count: number;
      upso_name: string;
      upso1: string;
      drug_form: string;
      dosage_route: string;
      charact: string;
      charact_new: string;
      cls_code: string;
      atc_cd: string;
      boh_history: string;
      boh_hiracode: string;
      item_permit_date: string;
      cancel_date: string;
      newdrug_class_code: string;
      bioeq_prodt_yn: string;
      comp_drug_yn_biology: string;
      comp_drug_yn_effect: string;
      comp_drug_yn: string;
      comp_drug_yn_physicochemical: string;
      kpic_atc: string;
      kpic_atc_cd: string;
      insertpaper: string;
      paper_dt: string;
      dur_age: string;
      dur_contra: string;
      dur_preg: string;
      dur_senior: string;
      dur_dose: string;
      dur_period: string;
      dur_donate: string;
      dur_form: string;
      fdacode: string;
      fdacontent: string;
      sunbcontent: string;
      drug_box: string;
      stmt: string;
      drug_pic: string;
      pack_img: string;
      picto_img: string;
      medititle: string;
      mediguide: string;
      effect: string;
      dosage: string;
      caution: string;
      idfylength: string;
      boh: string;
      etc: string;
      idfyidx: number;
      reexam: string | null;
      reexam_start_date: string;
      reexam_end_date: string;
      item_ingr_type: string;
      additives: string;
    }
  • MCP request handler dispatch case that extracts arguments, validates input, calls the core handler, and formats the MCP response.
    case 'get_drug_detail_by_id': {
      const { drugcode } = args as { drugcode: string };
      
      if (!drugcode) {
        throw new Error('drugcode parameter is required');
      }
    
      const result = await get_drug_detail_by_id(drugcode);
      
      return {
        content: [
          {
            type: 'text',
            text: result,
          },
        ],
      };
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

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/antegral/kpic-mcp'

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